首页 > 移动平台 > 详细

iOS 屏幕旋转 (对view做动画)

时间:2017-03-06 18:29:39      阅读:448      评论:0      收藏:0      [点我收藏+]

 

1.基于导航的试图控制器翻转,需要展示导航栏,因为不支持状态栏旋转,所以屏蔽了状态栏

  以下代码写在需要单独翻转的VC中。

 

- (void)viewDidLoad {

    [super viewDidLoad];

 //以下代码用于隐藏状态栏

    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {

        [self prefersStatusBarHidden];

        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)]

    }

}

- (BOOL)prefersStatusBarHidden {

    return YES;//隐藏为YES,显示为NO

}

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:YES];

 //视图将要显示时 翻转

    CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;//时间

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:duration];

    self.navigationController.view.transform = CGAffineTransformIdentity;

    self.navigationController.view.transform = CGAffineTransformMakeRotation(M_PI*1.5);//翻转角度

    self.navigationController.view.bounds = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width);

    [UIView commitAnimations];

}

- (void)viewWillDisappear:(BOOL)animated {

    [super viewWillDisappear:YES];

 //视图将要消失的时候 再把视图翻转回来 ,不会影响其他VC的展示

    CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:duration];

    self.navigationController.view.transform = CGAffineTransformIdentity;

    self.navigationController.view.transform = CGAffineTransformMakeRotation(M_PI*2);

    self.navigationController.view.bounds = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);

    [UIView commitAnimations];

}

 技术分享        技术分享

 

 

2. 不需要展示导航栏的,或者因为需求想要自定义导航栏的 ,只需要在 viewWillAppear 方法里面加上 隐藏导航栏的代码

self.navigationController.navigationBar.hidden = YES;

在 viewWillAppear 方法的翻转动画的代码中 改成对view做翻转就行,如下: 

    self.view.bounds = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);

    self.view.transform = CGAffineTransformMakeRotation(M_PI*1.5);

然后在视图将要消失的时候将导航栏的hidden再改为NO,注意 因为只是对当前vc的view做翻转,所以不会影响导航控制器,也就是当前页面的翻转不会影响到其他页面,

所以在viewWillDisappear里面 不需要再对view做旋转了。

 

iOS 屏幕旋转 (对view做动画)

原文:http://www.cnblogs.com/IOSwm/p/6511315.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!