如何阻止CATransform3DMakeScale动画缩放比例?

时间:2018-01-31 13:16:04

标签: ios objective-c animation calayer scaletransform

我在捏合手势期间使用CATransform3DMakeScale调用来调整CALayer的大小,但每个变换调用都会从原始缩放设置为目标缩放。

由于我将值从捏拉手势刻度传递到变换调用,因此手势刻度值的更新速度比导致口吃的变换动画更快。

- (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer {
    if ([gestureRecognizer state] == UIGestureRecognizerStateChanged) {
        pinchScale = [gestureRecognizer scale];
        CALayer *layer = [self layer];

        /* During pinching, this gets called again during the animation 
        of the last transformation */
        layer.transform = CATransform3DMakeScale(pinchScale, pinchScale, 0);
    }
}

如何阻止CATransform3DMakeScale动画转换?

1 个答案:

答案 0 :(得分:1)

您需要停用默认的CALayer动画机制添加此行

layer.actions = @{@"position": [NSNull null],@"frame":[NSNull null],@"bounds":[NSNull null]}; 

低于此CALayer *layer = [self layer];

或者您可以使用此方法获得相同的结果,这甚至更好,因为仅为此更改禁用动画并在此之后启用动画,如@Duncan在其评论中所述

[CATransaction begin];
[CATransaction setDisableActions:YES];

layer.transform = CATransform3DMakeScale(pinchScale, pinchScale, 0);
[CATransaction commit];