细胞轻扫事件和button触摸内部事件
我有一个表格单元格视图与4个UIButtons:
button有Touch Up Inside事件
@IBAction func increasDealRatingAction(sender:UIButton) { let buttonPosition = sender.convertPoint(CGPointZero, toView: self.tableView) if let indexPath = self.tableView.indexPathForRowAtPoint(buttonPosition) { ... } }
我有编辑每个单元格的操作:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { ... return [addToWishListAction, addToPurchasesAction, deleteAction] }
问题是,当您向左滑动以显示“添加到希望列表”,从“星形button”的位置“删除”动作时,单击也处理了事件,或者在button区域上滑动时滑动动作不会检测到。
向button添加滑动手势识别器
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
。