ios – 从当前比例缩放/缩放

前端之家收集整理的这篇文章主要介绍了ios – 从当前比例缩放/缩放前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
下面的代码正确地捏合/缩放容器视图,但只有在它跳转到1.0的标度之后.如何修改它以使容器视图从其当前比例缩放?
UIPinchGestureRecognizer *twoFingerPinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)];
[self.container addGestureRecognizer:twoFingerPinch];

- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer 
{
    _scale = recognizer.scale;
    CGAffineTransform tr = CGAffineTransformScale(self.view.transform,_scale,_scale);
    self.container.transform = tr;
}

解决方法

在.h文件中,添加
CGFloat _lastScale;

在.m文件中,

- (id)init  {
    ...
    _lastScale = 1.0f;
    ...
}

- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer 
{
    if (recognizer.state == UIGestureRecognizerStateEnded)  {
        _lastScale = 1.0f;
        return;
    }

    CGFloat scale = 1.0f - (_lastScale - recognizer.scale);
    CGAffineTransform tr = CGAffineTransformScale(self.view.transform,scale,scale);
    self.container.transform = tr;

    _lastScale = recognizer.scale;
}
原文链接:https://www.f2er.com/iOS/328562.html

猜你在找的iOS相关文章