Okay!
I have to clean up the code but it works.
One thing: For some reason it doesn't realy end with UIGestureRecognizerStateEnded...
The tag value is 0 that's fine... but the backgroundcolor doesn't alpha: 0.0
Here is the code:
UIPinchGestureRecognizer *twoFingerPinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)];
twoFingerPinch.cancelsTouchesInView = FALSE;
twoFingerPinch.delaysTouchesEnded = TRUE; // <---- this line is essential
[[self view] addGestureRecognizer:twoFingerPinch];
// some switch and the viewWithTag is my friend ;-)
- (void) twoFingerPinch:(UIPinchGestureRecognizer *) recognizer {
NSLog(@"Detected a pinch gesture");
CGPoint touchPoint = [recognizer locationInView:self.view];
NSLog(@"touchPoint: %@", NSStringFromCGPoint(touchPoint));
UIView *touchView = [self.view hitTest:touchPoint withEvent:nil];
switch (recognizer.state) {
case UIGestureRecognizerStateBegan:
NSLog(@"began");
if([touchView isKindOfClass:[UITextView class]]) {
touchView.tag = 1;
NSLog(@"touchView: %ld", (long)touchView.tag);
touchView.backgroundColor =[UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.5];
}
break;
case UIGestureRecognizerStateChanged:
NSLog(@"changed");
break;
case UIGestureRecognizerStateCancelled:
NSLog(@"cancelled");
touchView.tag = 0;
touchView.backgroundColor =[UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.0];
break;
case UIGestureRecognizerStateFailed:
NSLog(@"failed");
touchView.tag = 0;
touchView.backgroundColor =[UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.0];
break;
case UIGestureRecognizerStateEnded:
NSLog(@"ended");
touchView.tag = 0;
NSLog(@"touchView: %ld", (long)touchView.tag);
touchView.backgroundColor =[UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.0];
break;
default:
touchView.tag = 0;
touchView.backgroundColor =[UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.0];
break;
}
UITextView *myViewWithTag = (UITextView *)[self.view viewWithTag:1];
// UITextView *myViewWithTag = (UITextView *)recognizer.view;
UIFont *font = [myViewWithTag font];
CGFloat pointSize = [font pointSize];
NSString *fontName = [font fontName];
pointSize = ((recognizer.velocity > 0) ? 1.0 : -1.0) * 1 + pointSize;
if (pointSize < 13) pointSize = 13;
if (pointSize > 120) pointSize = 120;
[myViewWithTag setFont:[UIFont fontWithName:fontName size:pointSize]];
CGRect frame = myViewWithTag.frame;
frame.size.height = myViewWithTag.contentSize.height;
myViewWithTag.frame = frame;
}