ios – 在UIViewController上设置方向

ios – 在UIViewController上设置方向,第1张

概述我正在尝试设置UIViewController的方向,并禁止该UIViewController上的所有方向更改.重要的是要注意应用程序允许所有方向,但在这一个视图控制器上我想只允许纵向方向. 我正在使用iOS 8,该应用程序适用于iOS 6及更高版本.所描述的行为发生在iOS 7和8中.我无法在iOS 6中测试它,所以我不确定它是否发生在iOS 6中. 我实现了以下方法: - (BOOL)shou 我正在尝试设置UIVIEwController的方向,并禁止该UIVIEwController上的所有方向更改.重要的是要注意应用程序允许所有方向,但在这一个视图控制器上我想只允许纵向方向.

我正在使用iOS 8,该应用程序适用于iOS 6及更高版本.所描述的行为发生在iOS 7和8中.我无法在iOS 6中测试它,所以我不确定它是否发生在iOS 6中.

我实现了以下方法:

- (BOol)shouldautorotate{    return NO; // I've also trIEd returning YES - no success}- (NSUInteger)supportedInterfaceOrIEntations{    return UIInterfaceOrIEntationMaskPortrait; // I've also trIEd UIInterfaceOrIEntationPortrait - no success}- (UIInterfaceOrIEntation)preferredInterfaceOrIEntationForPresentation{    return UIInterfaceOrIEntationMaskPortrait; // Never called}

我已经能够设置模态呈现的视图控制器的方向,但我没有为该项目模态地呈现视图控制器.甚至可以这样做吗?

如何指定一个UIVIEwController的方向,而不影响其他UIVIEwControllers的方向?甚至可以这样做吗?

解决方法 假设您的视图控制器嵌入在导航控制器中,您需要使用UINavigationController的自定义子类并添加:

- (BOol)shouldautorotate;{    BOol shouldautorotate;    if ([self.topVIEwController respondsToSelector:@selector(shouldautorotate)])    {        shouldautorotate = [self.topVIEwController shouldautorotate];     }     else {        shouldautorotate = [super shouldautorotate];      }      return shouldautorotate;}- (NSUInteger)supportedInterfaceOrIEntations{    NSUInteger supportedOrIEntations;    if ([[self topVIEwController] respondsToSelector:@selector(supportedInterfaceOrIEntations)]) {        supportedOrIEntations = [[self topVIEwController] supportedInterfaceOrIEntations];    }    else {        supportedOrIEntations = [super supportedInterfaceOrIEntations];    }    return supportedOrIEntations;}

在导航控制器中.视图控制器中的方法很好,所以请保持原样.适用于iOS 7-8(尚未在iOS6中测试过)

总结

以上是内存溢出为你收集整理的ios – 在UIViewController上设置方向全部内容,希望文章能够帮你解决ios – 在UIViewController上设置方向所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1024667.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存