IOS开发 强制横屏

来源:互联网 发布:fedora25 yum 配置源 编辑:程序博客网 时间:2024/05/29 03:30

结合自身情况,加网络参考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];            } }


0 0
原创粉丝点击