本文主要是介绍IOS开发 强制横屏,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
结合自身情况,加网络参考http://blog.sina.com.cn/s/blog_76264a170101e5lb.html, 总结了自己写的方法:
在viewController里面添加:
-(void)controllerTransform{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];}}
-(void)viewDidAppear:(BOOL)animated{
[self performSelector:@selector(controllerTransform)];
}
-(void)viewDidDisappear:(BOOL)animated{
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 = UIInterfaceOrientationPortrait;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
}
这篇关于IOS开发 强制横屏的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!