ios - 使用 CATransform3DMakeRotation 平滑水平翻转

标签 ios core-animation

我设置了以下动画以在不同大小的 View 之间旋转。随着新的、更高的 View 进入视野,动画的中点似乎有一个闪烁。我可以做些什么来顺利过渡。

newView.layer.transform = CATransform3DMakeRotation(M_PI_2, 0.0, 1.0, 0.0);

[UIView animateWithDuration:0.5
                          delay:0
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{oldView.layer.transform = CATransform3DMakeRotation(M_PI_2, 0.0, -1.0, 0.0);}
                     completion:^(BOOL finished) {

                         [oldView removeFromSuperview];
                         [UIView animateWithDuration:0.5
                                               delay:0
                                             options:UIViewAnimationOptionCurveLinear
                                          animations:^{newView.layer.transform = CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 0.0);}
                                          completion:nil];

    }];

最佳答案

多亏了这个帖子,我才开始工作,所以我想我应该分享我使用 m34 矩阵进行的 3D 转换。

enter image description here

    UIView *toView = // show this
    UIView *fromView = // hide this one

    // set up from
    CATransform3D fromViewRotationPerspectiveTrans = CATransform3DIdentity;
    fromViewRotationPerspectiveTrans.m34 = -0.003; // 3D ish effect
    fromViewRotationPerspectiveTrans = CATransform3DRotate(fromViewRotationPerspectiveTrans, M_PI_2, 0.0f, -1.0f, 0.0f);

    // set up to
    CATransform3D toViewRotationPerspectiveTrans = CATransform3DIdentity;
    toViewRotationPerspectiveTrans.m34 = -0.003;
    toViewRotationPerspectiveTrans = CATransform3DRotate(toViewRotationPerspectiveTrans, M_PI_2, 0.0f, 1.0f, 0.0f);

    toView.layer.transform = toViewRotationPerspectiveTrans;

    [UIView animateWithDuration:1.0
                          delay:0
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{fromView.layer.transform = fromViewRotationPerspectiveTrans; }
                     completion:^(BOOL finished) {

                         [fromView removeFromSuperview];
                         [UIView animateWithDuration:1.0
                                               delay:0
                                             options:UIViewAnimationOptionCurveLinear
                                          animations:^{toView.layer.transform = CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 0.0);}
                                          completion:nil];

                     }];

关于ios - 使用 CATransform3DMakeRotation 平滑水平翻转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12565204/

相关文章:

ios - SplitViewController引用逻辑

ios - SWIFT:让我的应用程序获得使用互联网数据的高优先级

ios - 从另一个 View Controller 切换到 UIImageView 时,不会出现在第一次 View 中

ios - 动画在开始前延迟

ios - CALayer 属性(例如 : drop shadows) not appearing on all UITableViewCells

iphone - 核心动画缩放速度异常缓慢?

ios - 渐变动画——减速和加速

c++ - OpenCV:全景拼接 - 忽略图像的一部分

objective-c - 使用 CABasicAnimation 为 CAShapeLayer 的 strokeColor 设置动画

ios - Kontakt.io iOS - 按名称识别信标