用来控制当前视图控制器是否支持旋转
- (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;
   }
}
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
新闻名称:视图控制器旋转-创新互联
浏览地址:http://www.scyingshan.cn/article/dpdisi.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 