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);
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 总体方向两点: model下,present方式推出界面。 push横屏,带tabbar、navigation,且...
    sfandy阅读 46,781评论 90 99
  • 前言 最近在项目中有一个需求,就是进入某一个页面时要强制横屏,其他界面不做限制,查了资料发现有些方法对我的需求只有...
    不简单的风度阅读 1,932评论 0 3
  • 需求如下: 1.app整体只能竖屏,部分页面才可以横屏2.app整体只能竖屏,部分页面也是竖屏,但是点击某个按钮可...
    芝麻酱的简书阅读 2,242评论 3 7
  • //这段代码是强制产生横屏效果,通过kvo实现//强制右横屏 可以过审核-(void)viewWillAppea...
    梁大大大大大壮_阅读 1,422评论 2 1
  • 今天打坐看到团队的样子了 慢慢的浮现出来 自己感觉进步了很多 很多想法也不一样 这几天一直有事压在心里 感觉所有的...
    汐时阅读 228评论 0 0

友情链接更多精彩内容