I have an app that has a collectionView inside a scrollView. I am using the following code to be able to zoom in and pan around.
-(void) viewDidLoad {
[super viewDidLoad];
twoFingerPinchA = [[UIPinchGestureRecognizer alloc]
initWithTarget:self
action:@selector(twoFingerPinch:)]
;
[self.view addGestureRecognizer:(twoFingerPinchA)];
}
-(void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer{
CGAffineTransform transform = CGAffineTransformMakeScale(twoFingerPinchA.scale, twoFingerPinchA.scale);
if (twoFingerPinchA.scale < 1) {
twoFingerPinchA.scale = 1;
}
if (twoFingerPinchA.scale >2) {
twoFingerPinchA.scale = 2;
}
self.scrolling.transform = transform;
}
This works well except when I am zoomed in and remove my fingers. When I put my two fingers back on the screen to zoom out or in again the view returns to not zoomed in. How can I get the view to stay zoomed in when I replace my two fingers on the screen to rezoom. I have tried capturing the twoFingerPinchA.scale value which I can do. But I don't know how to set the initial value of the twoFingerPinchA.scale to that value as it alway returns to 1.
Any ideas?
So I am now trying to detect when two fingers touch the screen and when the two finger touch stops so I can save and insert the value of the twoFingerPinchA.scale.
However No matter what I put in I can't seem to detect the touches.
I have my controllers regular view, then I have a scroll view in it and then a collectionView inside of it.
I have enabled interaction and multiple touch for all views and tried to detect the touches in all view but don't get a call back. Here is my code.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Event:%@",event);
// I don't even get this call back as a touch beginning on any view.
if ([[event touchesForView:self.view] count] >0) {
NSLog(@"touches");
}
}