iphone - 按钮上的手势识别器

标签 iphone objective-c xcode uigesturerecognizer gesture-recognition

我想为按钮实现手势识别器(滑动 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/

相关文章:

iphone - 在 UITableview 上方添加搜索栏

iphone - 我如何/将实现莫尔斯电码生成器?

xcode - macOS 上的系统 llvm-config 在哪里?

ios - UISegmentedControl 操作中的 UIButton

iphone - iOS 中的动态自定义字体加载器

iphone - 从内部 View Controller 推送 View Controller

ios - 多次单击按钮时无法旋转图像

ios - 将多行文本放入动态改变大小的节点

objective-c - 哪个应用程序有键盘焦点?

ios - 如果使用cocoapods,如何保持标题路径?