我正在开发一个 iOS 应用程序,我希望在用户的手指滑入特定区域时产生操作效果。我首先认为拖动触摸的 UIButton 可以工作,但在“拖动”之前它仍然需要触摸。那么有没有办法做到呢?非常感谢!
最佳答案
您可以使用UITouch随着触摸开始。将您的特定区域 View 作为 UIView
IBOutlet。我们称之为preferredAreaView
也许是这样的:
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
let touch = touches.allObjects[0] as UITouch //get the latest touch
let touchLocation = touch.locationInView(self.view)
let particularAreaViewFrame = self.view.convertRect(particularAreaView.frame, fromView: self.view)
//Check if touch began is in your particularAreaViewFrame
if CGRectContainsPoint(particularAreaViewFrame, touchLocation) {
tiggerYourActionHere()
}
}
如果您需要它考虑移动到该区域的触摸,您还必须覆盖 touchesMoved: withEvent:
。然后也许可以将上面的内容重构为一个在两个地方都使用的函数。
关于ios - 当用户的手指滑入特定区域时是否可以触发 Action ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39825162/