作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
到目前为止,我已经有了一个按钮网格,并且已经将平移手势识别器附加到 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/
有没有一种方法可以“标记”对象的属性,使它们在反射中“突出”? 例如: class A { int aa, b; string s1, s2; public int AA
我是一名优秀的程序员,十分优秀!