Can I pass a pinch gesture recognizer to a ScrollView to have it zoom?

一世执手 提交于 2019-12-13 04:45:10

问题


I wrote a custom pinch gesture recognizer for my ScrollView's zooming, and I handle pinch touches in a method in my view controller.

But in some cases, I want the ScrollView to behave exactly as it would normally behave (if it used the standard pinch gesture recognizer that comes with ScrollView).

Is there some way that in such cases I can pass my custom gesture recognizer to the ScrollView and it would use that recognizer to scale the view as it normally would?

Could I pass the gesture recognizer to the selector that is triggered by pinch actions?


回答1:


I have not tried this, but here's an idea:

When you set your own gestureRecognizer, store the ScrollView's pinchGestureRecognizer in an iVar. You should then be able to dynamically exchange your gestureRecognizer and the original one.




回答2:


As of iOS 5 UIScrollView exposes a pinchGestureRecognizer property, but this is read-only. To get it to use your own instead you have to subclass UIScrollView and overwrite this property hoping that internally UIScrollView also uses this property to get the gesture recognizer to add when zooming is enabled.

However it is quite dangerous messing with scroll view's gesture recognizers, especially to modify their behavior. Even just having a different delegate will trigger an exception. So proceed at your own risk.



来源:https://stackoverflow.com/questions/11249402/can-i-pass-a-pinch-gesture-recognizer-to-a-scrollview-to-have-it-zoom

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