如何允许在滚动视图上触摸图像?
在我的程序中,我使用滚动视图作为背景视图。然后,我在滚动视图上添加几个图像。另外,我允许用户触摸图像以触发一些操作。但是,触摸滚动视图上附加的图像时无法检测到它们。我在触摸事件中使用以下代码:
UITouch * touch = [[event allTouches] anyObject];
我做错了什么吗?我该如何解决这个问题?非常感谢!
In my program, I use a scroll view as the background view. Then, I add several images on the scroll view. Also, I allow the users to touch the image in order to trigger some actions. However, the images attached on the scroll view cannot be detected when they were touched. I use the following code my the touch event:
UITouch * touch = [[event allTouches] anyObject];
Did I do something wrong? How can I solve this problem? Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 UIImageView 来跟踪触摸,并设置
myImageView.userInteractionEnabled = YES
,因为 imageview 的默认设置为 no。如果你想检测图像上的点击,你可以这样做:
并实现你的选择器:
You can use UIImageView to track touches, and also set
myImageView.userInteractionEnabled = YES
, since the default is no for imageviews.If you want to detect a tap on the image you can do this:
and implement your selector: