Simulating drags inside a scrollview

久未见 提交于 2019-12-12 17:29:09

问题


:) I am working on intercepting, and resending gestures sent to a scrollview.

What I want to do:

Kill all gestureRecognizers in the scrollview. I have accomplished this.

Add new gestureRecognizers in the scrollview. I have accomplished this as well.

Make the new recognizers behave the same as the old ones. I have NOT accomplished this, and I need help doing so.

The only new recognizer I have added is a pan gesture recognizer, which requires at least two fingers. I want this to behave exactly as a one finger scroll. :)

What kind of calls must I send when responding to the callbacks generated by the new recognizer to accomplish this?


回答1:


I think you've overcomplicated this by trying to implement your own custom gesture recogniser.

The UIPanGestureRecognizer class has a minimumNumberOfTouches property which you should be able to set to 2 for your UIScrollView.

To do so just grab your views gesture recognisers...

myScrollView.gestureRecognizers;

Iterate over the array to find the pan gesture...

if ([gestureRecogniser isKindOfClass:[UIPanGestureRecognizer class]])

Cast your gestureRecogniser pointer to the more specific type...

UIPanGestureRecognizer *panGestureRecogniser = (UIPanGestureRecognizer *)gestureRecogniser;

And finally set its minimumNumberOfTouches property...

panGestureRecogniser.minimumNumberOfTouches = 2;

The only other thing you may have to do is enabled multitouch for your view - UIView has a multipleTouchEnabled property that should be set to true.




回答2:


In Swift, You can just write

myScrollView.panGestureRecognizer.minimumNumberOfTouches = 2


来源:https://stackoverflow.com/questions/5125283/simulating-drags-inside-a-scrollview

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