iOS: Can I override pinch in/out behavior of UIScrollView?

前端 未结 4 1856
轮回少年
轮回少年 2020-12-19 13:21

I\'m drawing a graph on a UIView, which is contained by a UIScrollView so that the user can scroll horizontally to look around the entire graph.

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 14:24

    You should be able to subclass UIScrollView and override the touchesBegan: method. Don't call [super touchesBegan:] but instead, adjust the zoom as you like:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        //Anything you want. Probably you would want to store all the touches
        //or their values, so that you can compare them to the touches
        //in the touchesEnded: method, 
        //thus letting you know what the pinch amount was
    }
    

    If you like, you can judge whether it's a pinch or not, and if it's not, call the super method, and only handle it yourself for custom pinches.

提交回复
热议问题