如何从右上角动画/旋转UIView 90度? [英] How do I animate/rotate a UIView 90 degress from its upper right corner?

查看:180
本文介绍了如何从右上角动画/旋转UIView 90度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been searching for hours trying to find a way to animate/rotate a UIView 90 degrees from the upper right corner.

效果几乎应该像从屏幕顶部开出的一扇门。

The effect should almost work like a swinging door from the top of the screen.

希望有人可以提供帮助!

Hope someone can help!

推荐答案

所以在我按下回车后,我突然把两个和两个放在一起,并认为节拍器样品的工作方式就像一个摆动的门这让我有了一些其他的可能性。

So right after I pressed enter I suddenly put two and two together and figured the Metronome sample worked kind of like a swinging door and that led me to a few other possibilities.

这是我的解决方案:

- (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];
}

希望这也有助于其他人!

Hope this helps someone else too!

这篇关于如何从右上角动画/旋转UIView 90度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆