gpt4 book ai didi

ios - 使用 iOS 平移手势突出显示网格中的按钮

转载 作者:可可西里 更新时间:2023-11-01 01:05:32 24 4
gpt4 key购买 nike

到目前为止,我已经有了一个按钮网格,并且已经将平移手势识别器附加到 View 中。我可以跟踪事件并在手指移动时获取手指的位置,但似乎没有等效的“mouseEnter”消息可用于获取有关其他按钮的信息或控制属性(例如突出显示)我过去了。

我错过了什么吗?我怎样才能完成,比如说,在用户平移按钮时突出显示用户手指下方的按钮? cocoa touch 支持这个还是必须做其他事情?

谢谢。

最佳答案

你是对的,没有这样的事件。 UIButton 事件也不会帮助你,因为那些需要实际开始内部手势。您可以做的是获取当前拖动点的位置:

func panDetected(sender : MoreInformativeGestureRecognizer) {
let touchPoint = sender.locationInView(self.view)
}

现在,当你有了点时,你可以迭代你拥有的所有按钮并检查点是否在按钮内:

let buttons = [UIButton]
let lastActiveButton = UIButton?

...

// Iterate through all the buttons
for button in buttons {

// Check area of the button against your touch
if CGRectContainsPoint(button.frame, touchPoint) {

// You are inside the touch area of the button
// Here, you can for example perform some action if you want, store information
// about the button so you don't do it multiple times etc.. your call :)
self.lastActiveButton = button
}
}

通过这种方式,您可以检测然后进出并对事件做任何您想做的事情。希望对您有所帮助!

关于ios - 使用 iOS 平移手势突出显示网格中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31584514/

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