为了账号安全,请及时绑定邮箱和手机立即绑定

如何在iOS 6中使应用程序完全正常运行以实现自动旋转?

如何在iOS 6中使应用程序完全正常运行以实现自动旋转?

iOS
慕哥6287543 2019-12-27 10:27:30
在iOS6中,shouldAutorotateToInterfaceOrientation已弃用。我试图使用 supportedInterfaceOrientations和shouldAutorotate 制作应用程序的自转,但未能正常工作。我不想旋转此ViewController,但是它不起作用。- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{    return (interfaceOrientation == UIInterfaceOrientationPortrait);}-(BOOL)shouldAutorotate{    return NO;}-(NSUInteger)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskPortrait;}有任何想法吗?感谢您的任何帮助!
查看完整描述

2 回答

?
慕的地8271018

TA贡献1796条经验 获得超4个赞

弄清楚了。


1)子类化UINavigationController(层次结构的顶部viewcontroller将控制方向。)确实将其设置为self.window.rootViewController。


- (BOOL)shouldAutorotate

{

    return self.topViewController.shouldAutorotate;

}

- (NSUInteger)supportedInterfaceOrientations

{

    return self.topViewController.supportedInterfaceOrientations;

}

2)如果您不希望视图控制器旋转


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}


-(BOOL)shouldAutorotate

{

    return NO;

}


-(NSUInteger)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskPortrait;

}

3)如果您希望它能够旋转


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}


-(NSUInteger)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskAllButUpsideDown;

}


-(BOOL)shouldAutorotate

{

    return YES;

}

顺便说一句,根据您的需要,另一种相关方法:


- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{

     return UIInterfaceOrientationMaskPortrait;

}


查看完整回答
反对 回复 2019-12-27
?
浮云间

TA贡献1829条经验 获得超3个赞

如果您使用标签栏控制器而不是导航控制器作为根控制器,则需要类似地将UITabBarController子类化。


语法也会有所不同。我成功地使用了以下内容。然后,我在要覆盖的视图控制器上成功使用了上面的示例。就我而言,我希望主屏幕不旋转,但是我有一个带有电影的FAQ屏幕,我自然想启用横向视图。完美地工作!只需注意self.modalViewController的语法更改即可(如果尝试将语法用于导航控制器,则会收到编译器警告。)希望这会有所帮助!


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (BOOL)shouldAutorotate

{

    return self.modalViewController.shouldAutorotate;

}


- (NSUInteger)supportedInterfaceOrientations

{

    return self.modalViewController.supportedInterfaceOrientations;

}


查看完整回答
反对 回复 2019-12-27
  • 2 回答
  • 0 关注
  • 515 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信