ios - uiview翻转动画轴心问题
PHP中文网
PHP中文网 2017-04-17 13:19:53
[iOS讨论组]

我在view1的背面加上view2,view1翻转过来就显示view2,利用uiview动画UIViewAnimationOptionTransitionFlipFromRight实现。
问题是view1翻转的时候不是按照view1的中间轴心翻转,而是按self。view的轴心翻转,请问怎么解决这个问题?

[self.view1 sendSubviewToBack:self.view2]
[UIView transitionFromView:(self.view1)
toView:(self.view2)
duration: 2
options: UIViewAnimationOptionTransitionFlipFromLeft+UIViewAnimationOptionCurveEaseInOut
completion:^(BOOL finished) {
if (finished) {

                    }
                }
 ];
PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(1)
伊谢尔伦

文档中对于这个方法的定义有这么一段:

This method provides a simple way to transition from the view in the fromView parameter to the view in the toView parameter. By default, the view in fromView is replaced in the view hierarchy by the view in toView. If both views are already part of your view hierarchy, you can include the UIViewAnimationOptionShowHideTransitionViews option in the options parameter to simply hide or show them.

也就是说,将from从父类移除,将to移入。动画是基于父视图的。所以只需要在 view1和view2外面套上一个 container view 就可以了。

代码如下:

 UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];

    [self.view addSubview:containerView];

    UIView *fromView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerView.frame.size.width, containerView.frame.size.height)];
    fromView.backgroundColor = [UIColor blueColor];
    UIView *toView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerView.frame.size.width, containerView.frame.size.height)];
    toView.backgroundColor = [UIColor purpleColor];
    [containerView addSubview:fromView];

    [self.view addSubview:fromView];

    [CATransaction flush];

    [UIView transitionFromView:fromView toView:toView duration:0.4f options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL];
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号