我正在尝试在同一视图中实现捏合和旋转。有时捏取选择器被调用,有时旋转一个,好吧,但随后它会坚持下去。问题显然是gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
没有被调用。为什么不?得到明显的东西......
@interface FaceView : UIView <UIGestureRecognizerDelegate>
{
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
@end
@implementation FaceView
- (id)initWithFrame:(CGRect)frame
{
if( self = [super initWithFrame:frame] )
{
self.multipleTouchEnabled = YES;
self.userInteractionEnabled = YES;
UIRotationGestureRecognizer* rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)];
[self addGestureRecognizer:rotationRecognizer];
[rotationRecognizer release];
UIPinchGestureRecognizer* pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:)];
[self addGestureRecognizer:pinchRecognizer];
[pinchRecognizer release];
}
return self;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
NSLog(@"gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer");
return YES;
}
- (void)rotationGesture:(UIRotationGestureRecognizer*)gesture
{
switch( gesture.state )
{
case UIGestureRecognizerStateBegan:
NSLog(@"rotationGesture began");
break;
case UIGestureRecognizerStateChanged:
NSLog(@"rotationGesture changed");
break;
}
}
- (void)pinchGesture:(UIPinchGestureRecognizer*)gesture
{
switch( gesture.state )
{
case UIGestureRecognizerStateBegan:
NSLog(@"pinchGesture began");
break;
case UIGestureRecognizerStateChanged:
NSLog(@"pinchGesture changed");
break;
}
}
....
答案 0 :(得分:16)
我必须设置rotationRecognizer.delegate = self;
和pinchRecognizer.delegate = self;