ios强制横屏

在强制横屏的页面重新加载init方法:(ios8后会隐藏状态栏)

-(instancetype)init{

    self = [super init];

    //就是这句

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

    }

    return self;

}

ios8 以后横屏状态栏不显示

解决方法:

- (void)viewWillAppear:(BOOL)animated {
 
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
将页面设置成不可竖屏

在navigationcontroller中添加
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape
    ;
    
}

//是否支持屏幕旋转
- (BOOL)shouldAutorotate
{
    return  YES;
    
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation ==UIInterfaceOrientationLandscapeRight);
}

你可能感兴趣的:(ios强制横屏)