码迷,mamicode.com
首页 > 其他好文 > 详细

强制横竖屏间切换

时间:2015-09-17 23:26:27      阅读:478      评论:0      收藏:0      [点我收藏+]

标签:

if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        SEL selector = NSSelectorFromString(@"setOrientation:");
        
        if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
            NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
            [invocation setSelector:selector];
            [invocation setTarget:[UIDevice currentDevice]];
            int val = UIInterfaceOrientationPortrait;//
            [invocation setArgument:&val atIndex:2];
            [invocation invoke];
        }else{
            NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
            [invocation setSelector:selector];
            [invocation setTarget:[UIDevice currentDevice]];
            int val = UIInterfaceOrientationLandscapeRight;//
            [invocation setArgument:&val atIndex:2];
            [invocation invoke];
        }
    }

 

 

//屏幕旋转
-(BOOL)shouldAutorotate{
    return YES;
}
//支持旋转的方向
//一开始的屏幕旋转方向
//支持旋转的方向
//一开始的屏幕旋转方向
- (NSUInteger)supportedInterfaceOrientations
{
    NSLog(@"11222111111");

    return UIInterfaceOrientationLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

 

强制横竖屏间切换

标签:

原文地址:http://www.cnblogs.com/songxing10000/p/4817899.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!