iOS屏幕旋转与锁屏的示例代码

这篇文章主要介绍了iOS屏幕旋转与锁屏的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

在做视频开发时遇到屏幕旋转问题,其中涉及到 StatusBar、 UINavigationController、UITabBarController 、UIViewcontroller

在设备锁屏下的整体效果图

iOS-旋转.gif

主要涉及以下4点:

  • 横竖屏的旋转
  • 屏幕旋转相应改变视图位置
  • 旋转时状态栏的隐藏与显示
  • 锁屏

1、横竖屏旋转

第1步:


-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

//  NSLog(@"0000000---------%@",NSStringFromClass([[self topViewController] class]));
//  if ([NSStringFromClass([[self topViewController] class]) isEqualToString:@"FirstViewController"]) {
//    //横屏
//    return UIInterfaceOrientationMaskLandscapeRight;
//  }
//  //竖屏
//  return UIInterfaceOrientationMaskPortrait;
  
  NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;

  if(self.window.rootViewController){
    //取出当前显示的控制器
    UIViewController *presentedViewController = [self topViewControllerWithRootViewController:self.window.rootViewController];
    //按当前控制器支持的方向确定旋转方向(将旋转方向重新交给每个控制器自己控制)
    NSLog(@"%s, line = %d",__FUNCTION__,__LINE__);
    orientations = [presentedViewController supportedInterfaceOrientations];
  }

  return orientations;
}
//获取界面最上层的控制器
//- (UIViewController*)topViewController {
//  NSLog(@"%s, line = %d",__FUNCTION__,__LINE__);
//  return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
/

本文标题为:iOS屏幕旋转与锁屏的示例代码

基础教程推荐