2014-09-26 196 views
2

当呈现UIModalPresentationCustom的模式时,它将忽略方向方法,并显示/旋转到呈现VC配置的任何位置。UIModalPresentationCustom调整方向设置

  • 呈现VC支持横向和纵向。
  • 主办VC支持肖像(通过preferredInterfaceOrientationForPresentationsupportedInterfaceOrientations

当在景观呈现它没有UIModalPresentationCustom,它旋转视图回纵向,则呈现出VC相应。不幸的是,因为我需要的提出VC保持在下面可见,我不得不使用UIModalPresentationCustom当发生这种情况时,呈现的VC被强制进入横向模式,创建了一个混乱的用户界面并产生约束问题,即使以纵向呈现,它也可以旋转成景观,忽略shouldAutorotate返回编号

PS:我发现在iOS 7的解决方法,加入这个方法我的应用程序代理,但它不解决它在iOS 8

@implementation UIViewController (customModalFix) 

- (BOOL)shouldAutorotate 
{ 
    if ([self.presentedViewController isKindOfClass:[IntroViewController class]]) { 
     return [self.presentedViewController shouldAutorotate]; 
    } 
    return YES; 
} 

@end 

编辑:上呈现VC实现supportedInterfaceOrientations没有按根本没有帮助,因为只有当视图被加载时才会调用它,而不是当VC将要被呈现时才被调用。仍然没有找到解决这个问题的办法。

+0

我今天碰上了同样的问题,这里是解决方案: http://stackoverflow.com/a/29560217/1658831 – Pauls 2015-04-10 11:26:51

回答

0

也许我迟到了。关键是,使用UIModalPresentationCustom时,呈现的VC不会消失,并且呈现的VC不被视为全屏显示(即使它占用全屏)。因此,它是为支持的接口方向而咨询的呈现VC。因此,该解决方案可以像:

- (NSUInteger)supportedInterfaceOrientations 
{ 
    if (self.presentedViewController) { 
     return [self.presentedViewController supportedInterfaceOrientations]; 
    } 
    return [super supportedInterfaceOrientations]; 
} 
+0

谢谢您的回答,但不起作用。 - (NSUInteger)supportedInterfaceOrientations仅在第一次加载呈现时调用,而不是在呈现即将出现在屏幕上时调用。所以它永远不会通过条件如果(self.presentedViewController)。 – Anas 2014-10-07 08:52:31