目前,我正处于将ViewControllerA保持为纵向模式的中途。为此,我正在使用preferredInterfaceOrientationForPresentation
这样可以确保当我将ViewControllerA推入时,它将处于纵向模式。但是,如果我从ViewControllerA推到ViewControllerB,在ViewControllerB中切换到风景模式,然后再退回到ViewControllerA,则可以以风景模式显示ViewControllerA。我的愿望是继续对ViewControllerB进行多方向支持,但是强制ViewControllerA自动旋转为纵向。
另外,由于某种原因,ViewControllerA中似乎未调用shouldAutorotate。也许解决这个问题可以解决整个问题?
UINavigationController + Orientation.h类别
@interface UINavigationController (Orientation)
- (BOOL)shouldAutorotate;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
@end
UINavigationController + Orientation.m类别
-(BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
ViewControllerA.m
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
最佳答案
我遇到了同样的问题。我的解决方案如下,并且在发布的应用中。
我在AppDelegate.h中添加了一个名为allowViewRotation的公共属性:
@property (assign, nonatomic) BOOL allowViewRotation;
然后,我在AppDelegate.m文件中实现了以下调用:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { // if iPad
return UIInterfaceOrientationMaskAll;
}
if (self.allowViewRotation) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;
}
}
现在在ViewControllerA中将allowViewRotation属性设置为NO
((AppDelegate*)[UIApplication sharedApplication].delegate).allowViewRotation = NO;
并在ViewControllerB中将allowViewRotation属性设置为YES
((AppDelegate*)[UIApplication sharedApplication].delegate).allowViewRotation = YES;
注意:请确保在“部署信息”中启用了正确的设备方向
希望这可以帮助!
关于ios - 取消推送时,iOS 7强制纵向方向,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25769753/