Iphone 为什么赢了';我的图层是否围绕Z轴设置动画?

Iphone 为什么赢了';我的图层是否围绕Z轴设置动画?,iphone,cocoa-touch,core-animation,Iphone,Cocoa Touch,Core Animation,我有一个图像,我把它放在一个CALayer中,然后将该层添加为主视图的一个子层。当我尝试围绕Z轴设置动画时,我看到的只是一个静态图像 为什么我的图层不能设置动画?有关守则如下: - (void)viewDidLoad { UIImage *myImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"about" ofType:@"png"]]; earthLayer =

我有一个图像,我把它放在一个CALayer中,然后将该层添加为主视图的一个子层。当我尝试围绕Z轴设置动画时,我看到的只是一个静态图像

为什么我的图层不能设置动画?有关守则如下:

- (void)viewDidLoad {

    UIImage *myImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"about" ofType:@"png"]];
    earthLayer = [CALayer layer];
    [earthLayer setContents:(id)[myImage CGImage]];
    [earthLayer setBounds:CGRectMake(240,360, 40, 200)];
    [earthLayer setPosition:CGPointMake(280, 280)];
    [earthLayer setName:@"earth"];



    [earthLayer addAnimation:[self animationForSpinning] forKey:@"Rahul"];//here animatin is being added to the layer.. 

    [[self.view layer] addSublayer:earthLayer];

    //[self spinLayer:earthLayer];


}

//the animation method which returns a CAAnimation.

- (CAAnimation*)animationForSpinning {

    // Create a transform to rotate in the z-axis
    float radians = DegreeToRadian( 360 );
    CATransform3D transform;
    transform = CATransform3DMakeRotation(radians, 0, 1.0,0, 1.0);

    // Create a basic animation to animate the layer's transform
    CABasicAnimation* animation;
    animation = [CABasicAnimation animationWithKeyPath:@"transform"];

    // Now assign the transform as the animation's value. While
    // animating, CABasicAnimation will vary the transform
    // attribute of its target, which for this transform will spin
    // the target like a wheel on its z-axis. 
    animation.toValue = [NSValue valueWithCATransform3D:transform];

    animation.duration = 2;  // two seconds
    animation.cumulative = YES;
    animation.repeatCount = 10000;//  "forever"
    return animation;
}

您的问题似乎是试图使用360度变换来设置层的动画。对于核心动画,360度变换的层与起始层完全相同,因此不执行动画


如中所述,围绕
transform.rotation.z
关键路径设置动画时要执行的操作。这是Core Animation提供的辅助关键路径,由于起始值和结束值(旋转角度)不同,Core Animation不会进行与变换相同的优化。

在设置层动画之前,需要对层应用透视变换,否则你所做的旋转看起来就不对了

CATTransferorM3D transform=CATTransferorM3D实体; transform.m34=1.0/-2000

将层上的变换设置为该值,然后像您一样设置动画