简体   繁体   中英

GestureRecogniser and disabling drag gesture of a UIView in a UIScrollView

Recently I had a problem. How to disable scrolling in a particular area of a UIScrollView, particularly the area occupied by a UIView or subview. I've readen a lot about subclassing and other long approaches to solve this. But recently I solved this problem in a simplier manner without subclassing:

UIPanGestureRecognizer *panrecognizer = [[UIPanGestureRecognizer alloc] init];

and then

[panrecognizer setCancelsTouchesinView:NO];
[mySubViewInScroll addGestureRecognizer:panrecognizer];

I created the UIPanGestureRecognizer without an Action passed to it and then added the recognizer to the view in the scroller. In such way the gestures on the view will be captured but expressly not handled by the view or by the superviews because we passed to the object no Action. The question is this. Is this a correct approach to handle this type of prolem or it's better to do otherwise. I mean Apple will accept this kind of application with this approach ?

try rewrite ScrollView's

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

to return chi

In effect I think that this, even if not the best is the most practical solution..since messing around with the classes and subclassing to achieve only a partial scroll lock of the screen seems to be very odd. So let-s see if Apple will accept this kind of solution...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM