这篇文章主要介绍了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屏幕旋转与锁屏的示例代码
猜你喜欢
- 最好用的ios数据恢复软件:PhoneRescue for Mac 2023-09-14
- SurfaceView播放视频发送弹幕并实现滚动歌词 2023-01-02
- Android实现轮询的三种方式 2023-02-17
- Android MaterialButton使用实例详解(告别shape、selector) 2023-06-16
- 作为iOS开发,这道面试题你能答出来,说明你基础很OK! 2023-09-14
- Android实现监听音量的变化 2023-03-30
- Flutter实现底部和顶部导航栏 2022-08-31
- Android studio实现动态背景页面 2023-05-23
- iOS 对当前webView进行截屏的方法 2023-03-01
- 详解flutter engine 那些没被释放的东西 2022-12-04
