简体   繁体   中英

how to drag UIImageView under UIScrollView?

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.

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM