Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

objective c - UIScrollView and cancel a zooming pinch gesture

How do you forcibly cancel a zooming open pinch gesture on a UIScrollView, say when the user has zoomed "sufficiently" far to trigger a new action?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To prevent user-controller zooming and panning but still allow programmatic zooming and panning of a scrollview, the best approach is to override the UIScrollView's -addGestureRecognizer: method in a subclass.

-(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
    //Prevent any of the default panning and zooming controls from working
    gestureRecognizer.enabled = NO;
    [super addGestureRecognizer:gestureRecognizer];
    return;
}

Each gesture recognizer is simply disabled, for finer control (for ex. allowing the pan control but only allow zooming via a double tap for instance) you'd simply check the incoming gesture recognizer via -isKindOfClass: and disabling as appropriate.

-(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 
{
    //Prevent zooming but not panning
    if ([gestureRecognizer isKindOfClass:[UIPinchGestureRecognizer class]]) 
    {
        gestureRecognizer.enabled = NO;
    }
    [super addGestureRecognizer:gestureRecognizer];
    return;
}

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...