gpt4 book ai didi

ios - 当用户的手指滑入特定区域时是否可以触发 Action ?

转载 作者:行者123 更新时间:2023-11-30 13:01:54 25 4
gpt4 key购买 nike

我正在开发一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com