沿 X 轴(水平轴)旋转 UIView

发布于 2024-12-08 15:04:05 字数 791 浏览 0 评论 0原文

我想将 UIView 在其水平轴上旋转 360 度,然后刷新视图中的内容。我一直在寻找这方面的解决方案。在这里和那里发现了一对。这就是我得出的结果。

    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
        self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
    } completion:^(BOOL finished){
        NSLog(@"Finished first pi");
        [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
            self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
        }  completion:^(BOOL finished) {
            NSLog(@"Finished second pi");

        }];           

    }];

这会翻转视图,但仅翻转 180 度。我希望它再翻转一次,以便我可以正常看到视图。

我的两个 NSLog 都一个接一个地显示。我确信我在这里遗漏了一些东西。任何帮助都会有帮助..

谢谢

I wanted to rotate a UIView on its horizontal axis for 360 degrees and then refresh the content in the view. I was looking out for solutions on this. Found a couple here n there. This is what I came out with.

    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
        self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
    } completion:^(BOOL finished){
        NSLog(@"Finished first pi");
        [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
            self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
        }  completion:^(BOOL finished) {
            NSLog(@"Finished second pi");

        }];           

    }];

This flips the view but only by 180 degrees. I want it to flip one more time so that I can see the view normally..

Both my NSLogs are displayed one after the other. I am sure I am missing something here. ANy help would be helpful..

Thanks

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

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

发布评论

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

评论(5

甚是思念 2024-12-15 15:04:05

在完成块中尝试将新转换与当前转换连接起来。

self.tableView.layer.transform = CATransform3DConcat(self.tableView.layer.transform, CATransform3DMakeRotation(M_PI,1.0,0.0,0.0));

In your completion block try concatenating the new transform with the current transform.

self.tableView.layer.transform = CATransform3DConcat(self.tableView.layer.transform, CATransform3DMakeRotation(M_PI,1.0,0.0,0.0));
一场春暖 2024-12-15 15:04:05

您应该检查这个答案 如何使CATransform3dMakeRotation以另一种方式旋转?并链接在一起

我认为你的问题与:“当你直接使用变换时,核心动画会将变换从当前值插值到指定的变换。它将找到到达的最短路径该变换,这将限制动画方向。如果您尝试对同一变换属性进行两次动画处理,则第二个值将简单地覆盖第一个值,而不是将两个变换组合在一起。”

You should check this answer How to make a CATransform3dMakeRotation rotate the other way? And chain together

I think that your problem is related with: "When you are working with a transform directly, Core Animation will interpolate the transform from the current value to the specified transform. It will find the shortest path to get to that transform, which will restrict the animation direction. If you try to animate the same transform property twice, the second value will simply override the first, not combine the two transforms together."

不必了 2024-12-15 15:04:05

使用这个:-

  rotatingView.layer.anchorPoint = CGPointMake(0.0f, 0.0f);
    rotatingView.center = CGPointMake(0,
                                       (rotatingView.center.y -
                                        (rotatingView.bounds.size.height/2.0f)));
    rotatingView.center = CGPointMake(0,
                                      (rotatingView.center.y-
                                       (rotatingView.bounds.size.height/2)));

// start the Page Open
[UIView beginAnimations:@"Animation" context:nil];
[UIView setAnimationDuration:13.0];
// set angle as per requirement
[rotatingView.layer setValue:[NSNumber numberWithInt:280]
                   forKeyPath:@"transform.rotation.x"];

[UIView commitAnimations];

use this:-

  rotatingView.layer.anchorPoint = CGPointMake(0.0f, 0.0f);
    rotatingView.center = CGPointMake(0,
                                       (rotatingView.center.y -
                                        (rotatingView.bounds.size.height/2.0f)));
    rotatingView.center = CGPointMake(0,
                                      (rotatingView.center.y-
                                       (rotatingView.bounds.size.height/2)));

// start the Page Open
[UIView beginAnimations:@"Animation" context:nil];
[UIView setAnimationDuration:13.0];
// set angle as per requirement
[rotatingView.layer setValue:[NSNumber numberWithInt:280]
                   forKeyPath:@"transform.rotation.x"];

[UIView commitAnimations];
琴流音 2024-12-15 15:04:05

您只需在完成块内将代码从 1.0 更改为 0.0 就可以了。

 [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
            self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
        } completion:^(BOOL finished){
            NSLog(@"Finished first pi");
            [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
                self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,0.0,0.0,0.0);
            }  completion:^(BOOL finished) {
                NSLog(@"Finished second pi");

            }];           

        }];

You just have to change your code from 1.0 to 0.0 inside completion block and woohoo all done.

 [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
            self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
        } completion:^(BOOL finished){
            NSLog(@"Finished first pi");
            [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
                self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,0.0,0.0,0.0);
            }  completion:^(BOOL finished) {
                NSLog(@"Finished second pi");

            }];           

        }];
青春如此纠结 2024-12-15 15:04:05

您还可以使用 .Repeat.Autoreverse 动画选项 + 设置动画的重复次数来实现此目的。下面是 Swift 中的一个例子:

    UIView.animateWithDuration(time, delay: 0, options: [.Repeat, .Autoreverse], animations: {
        UIView.setAnimationRepeatCount(3)
        self.view.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI), 1, 0, 0)
    }) { (completed) in
        // completion
    }

You can also approach this using the .Repeat and .Autoreverse animation options + setting animation's repeat count. Here's an example in Swift:

    UIView.animateWithDuration(time, delay: 0, options: [.Repeat, .Autoreverse], animations: {
        UIView.setAnimationRepeatCount(3)
        self.view.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI), 1, 0, 0)
    }) { (completed) in
        // completion
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文