视图控制器 旋转

发布时间:2020-06-14 09:14:08 作者:缘起愿落
来源:网络 阅读:284


用来控制当前视图控制器是否支持旋转
- (BOOL)shouldAutorotate  // 自动旋转
{
    return YES;
}



设置屏幕旋转的方向,系统默认支持三个方向的旋转,竖直,左右横屏.
    UIInterfaceOrientationMaskPortrait 竖直方向 正方向
    UIInterfaceOrientationMaskLandscapeLeft 左横屏
    UIInterfaceOrientationMaskLandscapeRight 右横屏
    UIInterfaceOrientationMaskLandscape 左右 横屏


- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}



当屏幕将要旋转时触发(此时屏幕还未旋转)
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}


当屏幕旋转时触发.
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
 

在该方法中,如果想要在屏幕旋转时添加自己的动画,在该方法中实现.
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}



当屏幕旋转完成之后触发.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
      
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
     旋转之后,继续音乐播放,继续播放视频,打开用户交互.
}


当对视图控制器上的View布局时重新布局时 触发.
- (void)viewWillLayoutSubviews
{
    
    [super viewWillLayoutSubviews];

}




   释放掉暂时不使用的内存,供当前程序使用.
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
      Dispose of any resources that can be recreated.
     当收到内存警告时,移除未在当前屏幕显示的视图.
    
    判断是否可以安全的移除控制器的View
     判断当前视图控制器的view是否正在屏幕上显示. self.view.window 是否为nil;
    
  判断当前视图控制器的view是否已经成功加载. isViewLoaded 视图是否加载
    
    
    if (!self.view.window && [self isViewLoaded])
    {
         安全移除控制器的view
        self.view = nil;   相等于 [_view release]; _view = nil;
    }
 
    
}



 当屏幕每次旋转时都会触发视图的重新布局方法,为该视图上的子视图重新布局.
- (void)layoutSubviews
{
    [super layoutSubviews];
 
    
    对子视图重新布局.
    根据屏幕旋转的方向,决定布局的样式.
    1.获取屏幕旋转的方向 statusBarOrientation 状态条 高度 20
    
    switch ([UIApplication sharedApplication].statusBarOrientation) {
        case UIInterfaceOrientationPortrait:
  
    
            
        case UIInterfaceOrientationPortraitUpsideDown:
    
            break;
        case UIInterfaceOrientationLandscapeLeft:
     
           break;

        case UIInterfaceOrientationLandscapeRight:
            
 
            break;
            
        
        default:
            break;
    }
}

推荐阅读:
  1. php程序初学linux C
  2. thinkphp控制器怎样继承类

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

控制器 左右 return

上一篇:log4j日志文件配置说明及使用

下一篇:Spark Streaming高级特性在NDCG计算实践

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》