UIScrollview with two images - Keeping 1 image zoomable and 1 image static (fixed size)

会有一股神秘感。 提交于 2019-12-24 09:36:57

问题


I have a UIView which contains a zoomable UIImageView and also another semitransparent UIView on top of that.

What I am trying to achieve is to be able to zoom the UIImageView while keeping the semitransparent view static and not zoomed.

If I add the semitransparent UIView on top of the UIImageView (which is added to the UIScrollView), everything zooms. However, if I add both as subviews to the base UIView, the touches only get tracked is the semitransparent UIView since its the last one added.

I do need control to reside first at the semitransparent UIView for the touches since I may want to resize the semitransparent view. However, I'd like to pass control of the touches to the UIScrollView if two fingers are used. Is there anyway for me to achieve this? The nextresponder doesn't seem to work. I also tried to use hittest in addition to subclassing UIWindow, but the base UIView needs to push/pop navigation controlling ability so I don't think I can subclass UIWindow to push onto the navigation stack.

Any help would be appreciated.

Thanks,

Winston


回答1:


Hm.. you can try this hierarchy (possibly subclasses):

UIView (container)
 > UIView (semitransparent overlay)
 > UIScrollview
   - UIView (zoomable content)

Like this, the overlay does not scale.

The tricky thing then is the user interaction on multiple layers. Its easy if there are areas in your overlay that should not detect user touches, for that you just set the UIView property 'userInteractionEnabled' to 'NO' for the view parts where touches should be 'forwarded' to the underlaying layers.

But if I get you right, you need something more complicated. You probably could set up some kind of master-touch-controller in the container UIView, that finds out what is happening and then calls certain methods of its subviews / forwards the events. I don't know all the exact methods you need to override/implement in the container, but check out the tapZoom demo from the ScrollView Suite sample code. It's a pretty nice example there.

Just out of curiosity, may I ask what this interaction model is used for?



来源:https://stackoverflow.com/questions/2688789/uiscrollview-with-two-images-keeping-1-image-zoomable-and-1-image-static-fixe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!