如何获取 uiImage 视图的触摸事件?
我有一个名为 myImageView 的 UIImageView。 我需要为此 UIImageView 设置 userInteractionEnabled。 所以我用了 myImageView.userInteractionEnabled = YES;
但是 myImageView 仍然没有响应任何用户交互。
谁能告诉我一种在 myImage View 上启用触摸事件的好方法,并且我还需要在触发触摸事件时获取 myImageView 图像。有人可以帮助我吗?
i have a UIImageView named as myImageView.
i need to set the userInteractionEnabled for this UIImageView.
so i used myImageView.userInteractionEnabled = YES;
However still myImageView is not responding to any User interaction.
Can any one tell me a good way to enable touch event on myImage View and also i need to get the myImageView image , when touch event is triggered.can any one help me please..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在视图控制器中提供一个或多个触摸事件的实现,例如
touchesEnded:withEvent:
。该方法的第一个参数是触发事件的触摸集。您可以在文档。You need to provide an implementation for one or more of the touch events, such as
touchesEnded:withEvent:
, in your view controller. The first parameter to that method is the set of touches that triggered the event. You can get more details in the documentation.您可以使用自定义 UIButton 代替 UIImageView 并将其图像设置为要在 UIImageView 中显示的图像。然后您可以向其添加操作。
You could use a custom UIButton instead UIImageView of an and set its image to the image you want to display in the UIImageView. Then you can add an action to it.
其中drawImage是你的ImageView
Where drawImage is your ImageView