How to implement the traditional imageView-inside-a-scrollView pan gesture with two fingers instead of one?

大憨熊 提交于 2019-12-12 06:05:40

问题


I have an imageView nested inside of a scrollView that allows me to view an image, pinch to zoom, and pan around if I am zoomed in enough. Using a custom GestureRecognizer, I have (per the request of the person I'm building this app for) overridden the default behavior of the one finger pan so that it does something other than pan. This works perfectly.

Now the problem is that I still need the ability to pan around the image like I could with the one finger pan, I just need this to now be with two fingers. Is there a solution that can be implemented to utilize the already available features of the nested imageView? Or do I need to go through and after the two finger gesture is recognized, write my own custom pan-logic?

Any thoughts here are greatly appreciated!

Thanks


回答1:


With the newer versions if iOS you can merely adjust the parameters of the 'default' UIPanGenstureRecognizer that is already attached to the scrollView

    for (UIGestureRecognizer *gestureObj in scrollView.gestureRecognizers) {
    if ([gestureObj isKindOfClass:[UIPanGestureRecognizer class]])
    {
        UIPanGestureRecognizer *panObj = (UIPanGestureRecognizer *) gestureObj;
        panObj.minimumNumberOfTouches = 2;
        panObj.maximumNumberOfTouches = 2;
    }
}

That should 'shift' the behavior to the 2 finger level



来源:https://stackoverflow.com/questions/5454546/how-to-implement-the-traditional-imageview-inside-a-scrollview-pan-gesture-with

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