6

假设我想创建以下手势识别器

UITapGestureRecognizer * c1 = [[UITapGestureRecognizer alloc] 
          initWithTarget:self 
          action:@selector([[MyGestureRecognizer ViewWasClicked1:]]; // error 
[c1 setNumberOfTapsRequired:1];
[c1 setNumberOfTouchesRequired:1];
[[self view] addGestureRecognizer:c1];

但我想在一个单独的类上调用选择器。我有方法:

+ (void)ViewWasClicked1:(UITapGestureRecognizer *)sender {    

    NSLog(@"click1 mouse down");

}

在 MyGestureRecognizer 类中。我在寻找什么有可能吗?

4

2 回答 2

14

语法是:

UITapGestureRecognizer * c1 = [[UITapGestureRecognizer alloc] 
      initWithTarget:[MyGestureRecognizer class]
      action:@selector(ViewWasClicked1:)]; // error
于 2012-05-05T02:16:20.643 回答
1

要检查和调用静态方法,您可以这样做:

SEL staticMethodSelector = @selector(methodName);
if ([[ClassName class] respondsToSelector:staticMethodSelector]) {
    [[ClassName class] performSelector:staticMethodSelector];
}
于 2013-09-25T00:01:25.430 回答