关闭

IOS开发 强制横屏

202人阅读 评论(0) 收藏 举报

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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:63197次
    • 积分:2024
    • 等级:
    • 排名:第18986名
    • 原创:134篇
    • 转载:63篇
    • 译文:0篇
    • 评论:0条