小胖说事30------iOS 强制转成横屏的方式
2017-06-07 10:44
225 查看
一直遇到这个问题,今天最终找到了解决方法.
在我们的项目中常常遇到横竖屏切换,而又有某个特定的界面必须是特定的显示方式(横屏或竖屏).这就须要例如以下的处理了.
方法二: 通过推断状态栏来设置视图的transform属性。
说明一下:假设实现了下边的两个方法。你的应用程序在初始化的时候有多少个controller就会走多少次下边两个方法。showldAutorotate这种方法是再你即将旋转屏幕的时候,就会再次调用,仅仅要在这里推断好YES或者NO就好了。
在你须要的时候通过shouldAutorot这个变量打开,不须要的时候关闭就能够了。有什么不明确的,能够增加上边的QQ群。里边问我。
在我们的项目中常常遇到横竖屏切换,而又有某个特定的界面必须是特定的显示方式(横屏或竖屏).这就须要例如以下的处理了.
强制转成横屏: if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { SEL selector = NSSelectorFromString(@"setOrientation:"); NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; [invocation setTarget:[UIDevice currentDevice]]; int val = UIInterfaceOrientationLandscapeRight; [invocation setArgument:&val atIndex:2]; [invocation invoke]; }
方法二: 通过推断状态栏来设置视图的transform属性。
- (void)deviceOrientationDidChange: (NSNotification *)notification { UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; CGFloat startRotation = [[self valueForKeyPath:@"layer.transform.rotation.z"] floatValue]; CGAffineTransform rotation; switch (interfaceOrientation) { case UIInterfaceOrientationLandscapeLeft: rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 270.0 / 180.0); break; case UIInterfaceOrientationLandscapeRight: rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 90.0 / 180.0); break; case UIInterfaceOrientationPortraitUpsideDown: rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 180.0 / 180.0); break; default: rotation = CGAffineTransformMakeRotation(-startRotation + 0.0); break; } view.transform = rotation; }
说明一下:假设实现了下边的两个方法。你的应用程序在初始化的时候有多少个controller就会走多少次下边两个方法。showldAutorotate这种方法是再你即将旋转屏幕的时候,就会再次调用,仅仅要在这里推断好YES或者NO就好了。
在你须要的时候通过shouldAutorot这个变量打开,不须要的时候关闭就能够了。有什么不明确的,能够增加上边的QQ群。里边问我。
-(BOOL)shouldAutorotate //是否支持旋转。假设为NO,则下边的方法就不会调用,假设为YES,才会调用 { if (!shouldAutorot) { return NO; }else{ return YES; } } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; }
相关文章推荐
- 小胖说事30------iOS 强制转成横屏的方式
- iOS 强制转成横屏的方式
- iOS 强制转成横屏的方式
- iOS 强制转成横屏的方式
- iOS 强制转成横屏的方式
- 小胖说事48-----iOS 文本框变化 监听的3种方式
- ios 强制某个界面旋转成横屏
- iOS强制切换横屏、竖屏
- ios强制横屏之大山(三)
- ios 相机界面强制横屏
- iOS 强制横屏
- 小胖说事4------iOS 开启僵尸调试模式
- iOS 强制横屏
- 在iOS应用中从竖屏模式强制转换为横屏模式
- 小胖说事2------iOS 银联 支付宝sdk+demo+文档 支持64位
- (转)在IOS应用中从竖屏模式强制转换为横屏模式
- ios 强制某个界面旋转成横屏
- Xcode ,Cocos2d-x,强制横屏,Bundle Identifier ,iOS 打包成.ipa,修改项目名称,同名图片替换总是显示旧图片
- 小胖说事1------iOS存储密码_keychain
- IOS 应用中从竖屏模式强制转换为横屏模式