捏&旋转:未调用UIGestureRecognizerDelegate [英] Pinch & Rotate: UIGestureRecognizerDelegate not called

查看:33
本文介绍了捏&旋转:未调用UIGestureRecognizerDelegate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在同一视图中同时执行缩放和旋转.有时会调用收缩选择器,有时会旋转一次,确定,但随后会坚持下去.问题很明显是没有调用 gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer同时使用GestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 进行识别.为什么不?变得明显...

  @interface FaceView:UIView< UIGestureRecognizerDelegate>{}-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer应该使用GestureRecognizer同时识别:(UIGestureRecognizer *)otherGestureRecognizer;@结尾@implementation FaceView-(id)initWithFrame:(CGRect)框架{if(self = [super initWithFrame:frame]){self.multipleTouchEnabled =是;self.userInteractionEnabled = YES;UIRotationGestureRecognizer * rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture :)];[self addGestureRecognizer:rotationRecognizer];[rotationRecognizer发行];UIPinchGestureRecognizer * pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture :)];[self addGestureRecognizer:pinchRecognizer];[pinchRecognizer发行];}回归自我}-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer应该使用GestureRecognizer同时识别:(UIGestureRecognizer *)otherGestureRecognizer{NSLog(@"gestureRecognizer:应该使用手势识别器同时识别");返回是;}-(void)rotationGesture:(UIRotationGestureRecognizer *)手势{开关(gesture.state){案例UIGestureRecognizerStateBegan:NSLog(@"rotationGesture开始");休息;案例UIGestureRecognizerStateChanged:NSLog(@"rotationGesture已更改");休息;}}-(void)pinchGesture:(UIPinchGestureRecognizer *)手势{开关(gesture.state){案例UIGestureRecognizerStateBegan:NSLog(@"pinchGesture开始");休息;案例UIGestureRecognizerStateChanged:NSLog(@"pinchGesture已更改");休息;}}.... 

解决方案

我必须设置 rotationRecognizer.delegate = self; pinchRecognizer.delegate = self;

I'm trying to implement both a pinch and a rotate in the same view. Sometimes the pinch selector gets called and sometimes the rotation one, ok, but then it sticks with it. The problem is clearly that gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer isn't being called. Why not? Got to be something obvious...

@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;
    }
}
....

解决方案

I had to set rotationRecognizer.delegate = self; and pinchRecognizer.delegate = self;

这篇关于捏&amp;旋转:未调用UIGestureRecognizerDelegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆