简体   繁体   English

如何使我的自定义手势识别器类实例同时工作?

[英]How to make my custom gesture recognizer class instances work simultaneously?

You can download code example from this libk: https://github.com/mriddi/ExempleCustomGestureRecognizer.git 您可以从以下libk下载代码示例: https : //github.com/mriddi/ExempleCustomGestureRecognizer.git

I create my cusom gesture recognizer class like this: 我创建我的cusom手势识别器类,如下所示:

@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

My ViewController adopt MyGestureRecognizerDelegate protocol. 我的ViewController采用MyGestureRecognizerDelegate协议。 In ViewController I create instances of my class: ViewController我创建类的实例:

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

I want to make both gesture recognizers instances to work simultaneously. 我想使两个手势识别器实例同时工作。 I try to add to my ViewController method 我尝试添加到我的ViewController方法

shouldRecognizeSimultaneouslyWithGestureRecognizer 应该使用手势识别器同时识别

but this method never calls, I checked it using NSLog function. 但是此方法从不调用,我使用NSLog函数进行了检查。

Please help me solve this problem (allow work both gesture recognizers simultaneously). 请帮助我解决此问题(允许同时使用两个手势识别器)。

Maybe you should allocate the Gestures 也许您应该分配手势

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

Or you could use the control wheel as the target and do all your angle calculations in there. 或者,您可以将控制轮用作目标,并在那里进行所有角度计算。 Then you delegate back to the mainViewController. 然后,您委托回到mainViewController。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM