我想为按钮实现手势识别器(滑动 Action )。问题是,按钮是以编程方式创建的,并且根据一些条件存在或不存在。所以,我不知道是否有按钮,或者有多少。
我知道我需要这样的东西:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if (touch.view == aButtonView) {
//get the button's tag
}
}
当然,当按下任何按钮 View 时,if 语句应该返回 Yes...
有人知道 aButtonView
应该是什么意思吗?或者有可能吗?提前致谢。
最佳答案
您应该考虑使用 UISwipeGestureRecognizer
实例。将手势识别器附加到按钮对象 -
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSwipe:)];
swipe.direction = UISwipeGestureRecognizerDirectionUp;
[button addGestureRecognizer:swipe];
[swipe release];
并且在handleSwipe:
- (void) handleSwipe:(UISwipeGestureRecognizer *)swipe {
NSInteger tag = swipe.view.tag;
}
它应该是
if ( [gestureRecognizer.view isKindOfClass:[UIButton class]] ) {
关于iphone - 按钮上的手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6135483/