ios - 单元格滑动事件和按钮触摸事件内

标签 ios swift uigesturerecognizer

我有一个带有 4 个 UIButtons 的表格单元格 View :

enter image description here

按钮有 Touch Up Inside 事件

@IBAction func increasDealRatingAction(sender:UIButton) {
    let buttonPosition = sender.convertPoint(CGPointZero, toView: self.tableView)
    if let indexPath = self.tableView.indexPathForRowAtPoint(buttonPosition) {
       ...
    }
}

我对每个单元格都有编辑操作:

enter image description here

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    ...
    return [addToWishListAction, addToPurchasesAction, deleteAction]
}

问题是,当您向左滑动以显示“添加到愿望 list ”、“删除”星形按钮位置的操作时,点击事件也得到处理,或者在按钮区域滑动时未检测到滑动操作。

最佳答案

向按钮添加滑动手势识别器

let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:")) // nil for selector is also possible
swipeGestureRecognizer.direction = .Left // Add this if you want only one direction
dealRatingButton.addGestureRecognizer(swipeGestureRecognizer)
// Add three star buttons

并实现 gestureRecognizer(_:shouldReceiveTouch:) 返回 false

关于ios - 单元格滑动事件和按钮触摸事件内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34652981/

相关文章:

iOS。如何连续平移一系列 View ?

iOS:如何在运行时将应用程序背景分配给 UIView

android - Android 中的 UITextView(EditText?)

ios - UIApplicationDidEnterBackgroundNotification 多次调用 swift 2.0

ios - 快速从 API 调用传递 json 数组的所有成员

ios - 如何在iOS中识别旋转手势的开始和结束?

iphone - UIScrollView 和检测点击手势的 subview

ios - Microsoft OneDrive 是否允许业务合作伙伴在没有 Oauth 身份验证的情况下与其连接

ios - 字体在 iPhone 上不起作用

ios - 无法使用类型为 'enumerate' 的参数列表调用 '(String)'