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.
- 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?
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
精彩评论