Ios动画

iOS页面翻转

2018-02-03  本文已影响576人  追梦小怪兽
    //  来吧旋转动画
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        weakSelf.view.layer.transform = CATransform3DMakeRotation(M_PI/2.0, 0, 1, 0);  // 当前view,这句代码可以不要。这是我的需求
        UIWindow *window = [UIApplication sharedApplication].keyWindow;  
        window.layer.transform = CATransform3DMakeRotation(M_PI/2.0, 0, 1, 0);
    } completion:^(BOOL finished) {
        NewInfoViewController *newVC =[NewInfoViewController new];
        [weakSelf presentViewController:newVC animated:NO completion:nil];
    }];

在第二个界面中

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
        [UIView animateWithDuration:0 animations:^{
            self.view.layer.transform = CATransform3DMakeRotation(3*M_PI/2, 0, 1, 0);// 先将页面翻转270度。此时是你看不见这个控制器的,设置了alpha
        } completion:^(BOOL finished) {
            self.view.alpha = 1;
            [UIView animateWithDuration:0.5 animations:^{
                // 先将window 翻转270.
                UIWindow *window = [UIApplication sharedApplication].keyWindow;
                window.layer.transform = CATransform3DRotate(window.layer.transform,M_PI*3/2.0, 0, 1, 0);
                self.view.layer.transform = CATransform3DRotate(self.view.layer.transform, M_PI/2, 0, 1, 0);
            } completion:^(BOOL finished) {
            }];
        }];
    }
}

OK, 就这样搞定了需求。不要的有没有小伙伴还有更好的解决办法。希望小伙伴给点建议。
这里主要用到了 CATransform3DRotate 和 CATransform3DMakeRotation这2个方法。对x.y.z轴的翻转。
希望能帮助到需要的人。。

---来自涛胖子的工作笔记

上一篇 下一篇

猜你喜欢

热点阅读