开发者

how to drag UIImageView under UIScrollView?

开发者 https://www.devze.com 2023-02-26 21:21 出处:网络
I have a UIImageView (imageView) being the subView of the UIScrollView (scrollView). The scrollView is set only for pinching the showed开发者_StackOverflow中文版 image from imageView. And I have a sma

I have a UIImageView (imageView) being the subView of the UIScrollView (scrollView). The scrollView is set only for pinching the showed开发者_StackOverflow中文版 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.

  1. Can I simply use the "hitTest:withEvent:" method to work this out and how to use hitTest ?
  2. Or Should I override "UITouchesBegan:withEvent:" "UITouchesMoved:withEvent:" "UITouchesEnd:withEvent:" ? and how to use it?


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:

UITouchesBegan:withEvent:
UITouchesMoved:withEvent:
UITouchesEnd:withEvent:

Hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消