美文网首页
iOS强制横屏方法之一

iOS强制横屏方法之一

作者: 梁大大大大大壮_ | 来源:发表于2017-03-12 22:34 被阅读90次

//这段代码是强制产生横屏效果,通过kvo实现

//强制右横屏  可以过审核

-(void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];

[[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];

NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];

[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];

}



如果需要实现某些页面竖屏,特定页面横屏,可以使用模态推出页面方法,

首先

- (BOOL) shouldAutorotate

{

return NO;

}

然后添加这段代码

- (void) viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];

}

- (void) dealloc

{

[[NSNotificationCenter defaultCenter] removeObserver:self];

}

- (void)deviceOrientationDidChange

{

if([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {

[self orientationChange:NO];

} else if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {

[self orientationChange:YES];

}

- (void)orientationChange:(BOOL)landscapeRight

{

if (landscapeRight) {

[UIView animateWithDuration:0.4f animations:^{

self.view.transform = CGAffineTransformMakeRotation(M_PI_2);

self.view.bounds = CGRectMake(0, 0, Screen_Width, Screen_Height);

}];

} else {

[UIView animateWithDuration:0.4f animations:^{

self.view.transform = CGAffineTransformMakeRotation(0);

self.view.bounds = CGRectMake(0, 0, Screen_Width, Screen_Height);

}];

}

相关文章

  • iOS 强制横屏(Push和模态)

    # iOS 强制横屏(Push和模态) iOS开发过程中,有时候需要页面强制横屏。 下面这种方法是不管手机有没有开...

  • iOS强制横屏

    iOS强制横屏

  • iOS强制横屏方法之一

    //这段代码是强制产生横屏效果,通过kvo实现//强制右横屏 可以过审核-(void)viewWillAppea...

  • ios强制横屏

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

  • 强制横屏方法

    强制横屏: 方法一: 关于强制横屏看了很多文章,首先第一个方法是invocation,这个方法可以实现横屏效果,但...

  • iOS9之后强制横屏

    1、IOS8之后有的方法写到类里强制横屏之后已经没有用了 2、IOS8之后该怎么实现强制横屏 首先在代理类实现该方...

  • iOS横屏的深入研究

    iOS横屏模式分2种:跟随系统自动旋转、强制横屏。无论哪种横屏模式,都有2中实现途径:1.重写系统旋转方法。2.对...

  • 横竖屏

    需求: 让push的ViewController界面强制横屏 一、配置 二、添加强制横屏方法 pragma mar...

  • iOS强制转屏

    引言 遇到需要转屏的功能,查资料刚好看到一篇iOS强制横屏或强制竖屏,不过发现里面的方法有点太不可取,做了下修改。...

  • iOS 部分界面强制横屏与强制竖屏

    最新屏幕强制旋转详见 强制横屏(此方法为旋转视图) 恢复竖屏

网友评论

      本文标题:iOS强制横屏方法之一

      本文链接:https://www.haomeiwen.com/subject/iebxnttx.html