我创建了一个自定义Button类。我有一个UITapGestureRecognizer
来识别水龙头并根据需要做出响应:
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
recognizer.numberOfTapsRequired = 1;
recognizer.numberOfTouchesRequired = 1;
recognizer.cancelsTouchesInView = YES;
self.recognizer = recognizer;
[buttonView addGestureRecognizer:recognizer];
我创建按钮并添加目标:
[buttonList addTarget:self action:@selector(buttonListSelected)];
-(void)addTarget:(id)target action:(SEL)action {
[self.recognizer addTarget:target action:action];
}
当我创建action方法并要求它返回类时:
-(void)buttonSortSelected:(SubButton *)subButton {}
返回UITapGestureRecognizer
。
我可以进行设置,以便自定义类会返回self
而不是识别器吗?
答案 0 :(得分:1)
如果您想自己更改必须处理tapDetected:
的参数。
// In your custom button class
-(void)addTarget:(id)target action:(SEL)action {
self.target = target;
self.targetedSelector = selector;
}
然后
// In your custom button class
- (void)tapDetected:(UITapGestureRecognizer *)recognizer {
[self.target performSelector:self.targetedSelector withObject:self];
}