如何将UIImageView拖到UIScrollView下面?
我有一个 UIImageView (imageView) 是 UIScrollView (scrollView) 的子视图。设置scrollView仅用于从imageView中捏合显示的图像。我有一个小的 UIImageView (iconView),它是 imageView 的子视图。所以关系是这样的:
UIView |_____ UIScrollView ( 滚动视图 ) |_____ UIImageView (imageView) |______ UIImageView(iconView) 。
我需要触摸并移动 iconView,但我对我发现的这两种方法感到困惑。
- 我可以简单地使用“hitTest:withEvent:”方法来解决这个问题以及如何使用 hitTest 吗?
- 或者我应该覆盖 "UITouchesBegan:withEvent:" "UITouchesMoved:withEvent:" "UITouchesEnd:withEvent:" 吗?以及如何使用它?
I have a UIImageView (imageView) being the subView of the UIScrollView (scrollView). The scrollView is set only for pinching the showed image from imageView. And I have a small UIImageView (iconView) which is the subView of imageView. So the relationship is like:
UIView |_____ UIScrollView ( scrollView ) |_____ UIImageView (imageView) |______ UIImageView(iconView) .
I need to touch and move the iconView but I am confused with this two methods I found.
- Can I simply use the "hitTest:withEvent:" method to work this out and how to use hitTest ?
- Or Should I override "UITouchesBegan:withEvent:" "UITouchesMoved:withEvent:" "UITouchesEnd:withEvent:" ? and how to use it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该使用第二种方法。
对 UIView 类进行子类化并创建 CustomView。将 iconView 定义为 CustomView。
在 CustomView 中定义 3 个代表所需的行为:
希望这有帮助
You should use the 2nd method.
Subclass the UIView class and create CustomView. Define iconView as CustomView.
In CustomView define the 3 delegates to the desired behaviour:
Hope this helps