开发者

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

开发者 https://www.devze.com 2022-12-18 15:39 出处:网络
What is this 0 to 1 thing exactly? How could I rotate the layer absolutely to 170 degrees, for example?

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

精彩评论

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

关注公众号