开发者

How to rotate this view to a specific value in radians or degrees?

What is this 0 to 1 thing exactly? How could I rotate the layer absolutely to 170 degrees, for example?

CALayer* viewLayer = myView.layer;
    CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    animation.fromValue = [NSNumber numberWithFloat:0.0 * M_PI];
    animation.toVa开发者_运维百科lue = [NSNumber numberWithFloat:1.0 * M_PI];

    animation.duration = 1.0;
    animation.cumulative = YES;
    animation.repeatCount = 2;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;

    [viewLayer addAnimation:animation forKey:@"transform.rotation.z"];


Not knowing an Cocoa, I would say that the toValue specifies 1.0Pi radian rotation. There are 2Pi radians in 360 degrees. Hence 1.0Pi represents 180 degrees. To get a 170 degree rotation I would set toValue as

animation.toValue = [NSNumber numberWithFloat:(170.0/180.0) * M_PI];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜