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];
        
    }
 
}





阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tiebanshao/article/details/51538746
上一篇IOS开发 控制器强制转换为横屏
下一篇xcode 左边导航栏中,类文件后面的标记“A”,"M","?"……等符号的含义???
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭