ios - 如何为uiview的不同部分添加多个UITapGestureRecognizer?

标签 ios swift uitapgesturerecognizer

假设我有一个宽度为 100 的 UIView

是否可以添加 2 个手势识别器,如下所示:

rightTapGesture 用于 View 的右侧 50 以及 leftTapGesture 用于其他 50 个 View ?

不过我不能使用选项卡式按钮!

最佳答案

在你的UIGestureRecognizerDelegate中:

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
    switch gestureRecognizer {
    case leftTapGesture:
        return touch.locationInView(theView).x < 50
    case rightTapGesture:
        return touch.locationInView(theView).x >= 50
    default:
        // cannot be here
        return false
    }
}

关于ios - 如何为uiview的不同部分添加多个UITapGestureRecognizer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32409442/

相关文章:

ios - 重用 UIViewController

android - 数据库兼容性 : Building a database to support apps across multiple OSs

json - 如何过滤 API 响应以在 Swift 中包含/排除 TableView 中的一些数据

ios - 以编程方式将自定义 UIViewcontroller 添加到 subview 但收到错误消息 "Cannot convert value of type..."

ios - UITapGestureRecognizer 不会取消 UITableView 元素上的点击

ios - UITapGestureRecognizer 不适用于自定义 UIView 类

ios - 从 iOS 中的文档目录中按特定文件名检索

ios - 从 ios 应用程序在 QuickBlox 中注册新用户时终止应用程序

ios - swift 4错误的json数组解析

ios - 如何为 Collection View 单元格内的 View 添加手势?