0

您可以从此 libk 下载代码示例: https ://github.com/mriddi/ExempleCustomGestureRecognizer.git

我像这样创建我的自定义手势识别器类:

@protocol MyGestureRecognizerDelegate <UIGestureRecognizerDelegate>
@optional
-(void) willDo;
@end

@interface MyGestureRecognizer: UIGestureRecognizer
{
    …
}
@property (nonatomic, assign) id <MyGestureRecognizerDelegate> delegate;
…
@end

@implementation MyGestureRecognizer
@synthesize delegate;
…
-(void) call{
    [delegate willDo];
}
…
@end

我的 ViewController 采用MyGestureRecognizerDelegate协议。在ViewController我创建我的类的实例:

MyGestureRecognizer * grFerst;
MyGestureRecognizer * grSecond;
grFerst.delegate=self;
grLeft.delegate=self;
[self.view addGestureRecognizer: grFerst];
[self.view addGestureRecognizer: grSecond];

我想让两个手势识别器实例同时工作。我尝试添加到我的ViewController方法中

shouldRecognizeSimultaneouslyWithGestureRecognizer

但是这个方法从不调用,我用NSLog函数检查了它。

请帮我解决这个问题(允许同时使用两个手势识别器)。

4

1 回答 1

1

也许你应该分配手势

MyGestureRecognizer * gesture = [[MyGestureRecognizer alloc] initWithTarget:self action:nil];
gesture.delegate = self;
[self.view addGestureRecognizer:gesture];

或者您可以使用控制轮作为目标并在那里进行所有角度计算。然后你委托回 mainViewController。

于 2012-12-13T19:31:30.057 回答