资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

iOS屏幕旋转与锁屏的示例代码-创新互联

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

成都创新互联从2013年成立,先为郏县等服务建站,郏县等地企业,进行企业商务咨询服务。为郏县企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

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

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

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];
//}
//一层一层的进行查找判断
- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {
  NSLog(@"%s, line = %d",__FUNCTION__,__LINE__);
  if ([rootViewController isKindOfClass:[UITabBarController class]]) {
    
    UITabBarController* tabBarController = (UITabBarController*)rootViewController;
    NSLog(@"Tabbar:%@",NSStringFromClass([tabBarController.selectedViewController class]));

    return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
  } else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
    
    UINavigationController* nav = (UINavigationController*)rootViewController;
    NSLog(@"nav:%@",NSStringFromClass([nav.visibleViewController class]));
    return [self topViewControllerWithRootViewController:nav.visibleViewController];
  } else if (rootViewController.presentedViewController) {
    NSLog(@"present:%@",NSStringFromClass([rootViewController.presentationController class]));
    UIViewController* presentedViewController = rootViewController.presentedViewController;
    return [self topViewControllerWithRootViewController:presentedViewController];
  } else {
    NSLog(@"root:%@",rootViewController);
    return rootViewController;
  }
}

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享题目:iOS屏幕旋转与锁屏的示例代码-创新互联
当前URL:http://cdkjz.cn/article/hgdjs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220