如何从右上角动画/旋转UIView 90度?

dan*_*dax 7 core-animation transform rotation uiview ios

我一直在寻找几个小时试图找到一种方法来动画/旋转UIView从右上角90度.

效果应该像屏幕顶部的摆动门一样.

希望有人可以帮忙!

dan*_*dax 25

因此,在我按下回车后,我突然将两个和两个放在一起,并认为节拍器样品的工作类似于摆动门,这使我有了一些其他的可能性.

这是我的解决方案:

- (void)viewDidLoad {
    [super viewDidLoad];

    // Set the anchor point and center so the view swings from the upper right
    swingView.layer.anchorPoint = CGPointMake(1.0, 0.0);
    swingView.center = CGPointMake(CGRectGetWidth(self.view.bounds), 0.0);

    // Rotate 90 degrees to hide it off screen
    CGAffineTransform rotationTransform = CGAffineTransformIdentity;
    rotationTransform = CGAffineTransformRotate(rotationTransform, DegreesToRadians(90));
    swingView.transform = rotationTransform;
}

...

- (void)animateSwing {

    CGAffineTransform swingTransform = CGAffineTransformIdentity;
    swingTransform = CGAffineTransformRotate(swingTransform, DegreesToRadians(0));

    [UIView beginAnimations:@"swing" context:swingView];
    [UIView setAnimationDuration:0.25];

    swingView.transform = swingTransform;

    [UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)

希望这也有助于其他人!

  • #define DEGREES_RADIANS(角度)((角度)/ 180.0*M_PI) (2认同)