用按钮触摸移动?
是否可以使用带有按钮的 touchesMoved
函数而不是 UIImageView
?
Is it possible to use the touchesMoved
function with buttons instead of UIImageView
s?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。
在 .h 文件
中 在 .m 文件中
最后,在 Interface Builder 中,将按钮连接到“aButton”并关闭按钮的“用户交互启用”。
这很重要,因为它允许 TouchMoved 来处理它。
我已经调整了上面的代码来检查按钮突出显示的状态。这是为了防止当您将手指拖动到该区域时多次触发按钮。
要让“钢琴键”在点击时起作用,请使用
-(void)touchesBegan
要将按钮突出显示状态设置回
= NO;
,请使用-(void)touchesEnded
我必须找出你所追求的完全相同的东西。我无法弄清楚
Touch Drag Enter
因此,为了避免就该主题发表多个帖子,请查看我的问题和答案。
问题 1
问题 2
Yes.
In your .h file
In your .m file
And finally, in Interface Builder, connect your button to 'aButton' and turn off "User Interaction Enabled" for your button.
This is important because it allow touchesMoved to handle it.
I have adjusted the code above to check the buttons highlighted state. This is to stop it from firing the button multiple times when you drag your finger inside the area.
To get your "piano keys" to work when you tap them, use
-(void)touchesBegan
To set your button highlight states back to
= NO;
, use-(void)touchesEnded
I have had to find out the exact same thing you are after. I couldn't figure out
Touch Drag Enter
So to avoid multiple posts on the subject, please check out my question and answers.
question 1
question 2
您肯定会发现当前正在触摸事件的“视图”正在被拖动,即使它是一个按钮。您还可以在 Interface Builder 中使用按钮的“触摸拖动输入”连接。选择按钮后按 cmd+2 查看连接选项卡。
You could certainly find the 'view' that is currently being touch event is dragging over even if it is a button. You could also use the 'touch drag enter' connection for buttons in the Interface Builder. Look at the connections tab by pressing cmd+2 when having selected a button.