代码之家  ›  专栏  ›  技术社区  ›  Brian Liang

CGaffilinetransformmakerotation在变基之前

  •  3
  • Brian Liang  · 技术社区  · 14 年前

    在执行旋转动画之前,我首先执行uiImageView的旋转:

    // rotate to the left by 90 degrees
    someView.transform = CGAffineTransformMakeRotation((-0.5)*M_PI);
    

    然后在视图上旋转180度…但它似乎是从原始位置开始旋转图像,就好像它不是最初旋转的一样。

    - (void)rotateIndicatorToAngle: (UIView *)view angle: (NSNumber *)angleInDegrees
    {
        CALayer *layer = view.layer;
        CGFloat duration = 5.0;
        CGFloat radians = [self ConvertDegreesToRadians: [angleInDegrees floatValue]];
        CABasicAnimation* rotationAnimation;
        rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        rotationAnimation.toValue = [NSNumber numberWithFloat: radians];
        rotationAnimation.duration = duration;
        rotationAnimation.cumulative = YES;
        rotationAnimation.repeatCount = 1.0;
        rotationAnimation.removedOnCompletion = NO;
        rotationAnimation.fillMode = kCAFillModeForwards;
        rotationAnimation.timingFunction = [CAMediaTimingFunction
    functionWithName:kCAMediaTimingFunctionEaseOut];
    
    [layer addAnimation: rotationAnimation forKey: @"rotationAnimation"];
    }
    

    给出了什么?

    2 回复  |  直到 14 年前
        1
  •  4
  •   jv42    14 年前

    rotationAnimation.cumulative = YES;

    你试过用吗 rotationAnimation.additive = YES; 而不是累积?

        2
  •  2
  •   jv42    14 年前

    您可以使用 UIView 要轻松设置视图动画:

    [UIView beginAnimation: @"Rotate" context: nil];
    [UIView setAnimationDuration: 5.0f];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
    
    CGFloat radians = [self ConvertDegreesToRadians: [angleInDegrees floatValue]];
    view.transform = CGAffineTransformMakeRotation(radians);
    
    [UIView commitAnimation];
    

    这就是我大部分时间使用的,不需要使用层。

    更新:我的意思是,在这种情况下,我发现不使用层更容易,在使用层上没有贬低的价值。