如何转换(旋转)已存在的CALayer /动画?

时间:2010-03-31 02:53:29

标签: iphone uiview transform calayer

我在我的应用程序的UIView中添加了一个CALayer:

    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];
    [animation setDuration:0.35];
    [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
        animation.type = @"pageCurl";
        animation.fillMode = kCAFillModeForwards;
        animation.endProgress = 0.58;
    [animation setRemovedOnCompletion:NO];
    [[self.view layer] addAnimation:animation forKey:@"pageCurlAnimation"];

现在,当用户旋转设备时,图层始终保持在屏幕上的相同位置(与主屏幕按钮对齐)。是否可以旋转动画/图层?我试过了

self.view.layer.transform = CGAffineTransformMakeRotation (angle);

但是这段代码只是旋转UIView而不是我设置的动画/图层。

1 个答案:

答案 0 :(得分:4)

错误是因为CALayer的transform属性的类型是CATransform3D,并且你给它一个CGAffineTransform。使用 CATransform3D CATransform3DMakeRotation(CGFloat角,CGFloat x,CGFloat y,CGFloat z); 代替。