如何降低捏缩放UIGestureRecognizer的速度 [英] How to reduce velocity of pinch-zoom UIGestureRecognizer

查看:68
本文介绍了如何降低捏缩放UIGestureRecognizer的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了UIGestureRecognizer,非常类似于

I've created a UIGestureRecognizer much like this one:

- (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer {

    if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
        // Reset the last scale, necessary if there are multiple objects with different scales
        lastScale = [gestureRecognizer scale];
    }

    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || 
        [gestureRecognizer state] == UIGestureRecognizerStateChanged) {

        CGFloat currentScale = [[[gestureRecognizer view].layer valueForKeyPath:@"transform.scale"] floatValue];

        // Constants to adjust the max/min values of zoom
        const CGFloat kMaxScale = 2.0;
        const CGFloat kMinScale = 1.0;

        CGFloat newScale = 1 -  (lastScale - [gestureRecognizer scale]); 
        newScale = MIN(newScale, kMaxScale / currentScale);   
        newScale = MAX(newScale, kMinScale / currentScale);
        CGAffineTransform transform = CGAffineTransformScale([[gestureRecognizer view] transform], newScale, newScale);
        [gestureRecognizer view].transform = transform;

        lastScale = [gestureRecognizer scale];  // Store the previous scale factor for the next pinch gesture call  
    }
}

这可以按预期工作,但是我的客户希望其对触摸的敏感度 .如何减小捏合速度(向内和向外),使其放大到默认速度的80%左右?

This works as expected, however my client wants it to be less sensitive to touch. How can I reduce the velocity of the pinching (both inward and outward) so that it zooms at about 80% the default velocity?

推荐答案

事实证明,缩放速度过快实际上是链接的答案代码中的错误.遗憾的是,这实际上并不能回答我的实际问题(我仍然想回答这个问题!),但确实可以解决客户的问题.

Turns out the excessive speed of the zoom was actually a bug in the linked answer's code. Sadly this doesn't actually answer my actual question though (for which I'd still like an answer!), but it does serve to solve my client's problem.

请注意在底部添加的行,该行将手手势识别器重置为1:

Note the added line at the bottom that resets the gestureRecognizer back to 1:

- (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer {

        ...

        lastScale = [gestureRecognizer scale];  // Store the previous scale factor for the next pinch gesture call  

        gestureRecognizer.scale = 1;
        // ^ added this line
    }
}

这篇关于如何降低捏缩放UIGestureRecognizer的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆