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

发布于 2024-09-30 08:17:06 字数 94 浏览 6 评论 0原文

我花了几个小时试图找到一种方法来将 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尛丟丟 2024-10-07 08:17:06

因此,在我按下回车键后,我突然将两个和两个放在一起,并认为节拍器示例的工作方式有点像一扇旋转门,这让我想到了其他一些可能性。

这是我的解决方案:

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

希望这对其他人也有帮助!

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.

Here's my solution:

- (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!

灯角 2024-10-07 08:17:06

您应该尝试将图层的锚点设置为 (0,1),然后对图层进行动画处理。

You should try setting the anchor point of the layer to (0,1), and than animate the layer.

我为君王 2024-10-07 08:17:06

你应该尝试这个代码:

-(void)doRotationView{
[UIView beginAnimations:@"flipping view" context:nil];  
    [UIView setAnimationDuration:1];    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];   
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft    
                           forView:self cache:YES];
    if (flagFront == 1) {
        flagFront =0;
        [self.viewSecond setHidden:NO];
        [self.viewFirst setHidden:YES];
    }
    else{
        flagFront =1;
        [self.viewSecond setHidden:YES];
        [self.viewFirst setHidden:NO];        
    }
    [UIView commitAnimations];

}

You should try this code:

-(void)doRotationView{
[UIView beginAnimations:@"flipping view" context:nil];  
    [UIView setAnimationDuration:1];    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];   
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft    
                           forView:self cache:YES];
    if (flagFront == 1) {
        flagFront =0;
        [self.viewSecond setHidden:NO];
        [self.viewFirst setHidden:YES];
    }
    else{
        flagFront =1;
        [self.viewSecond setHidden:YES];
        [self.viewFirst setHidden:NO];        
    }
    [UIView commitAnimations];

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文