我一直在互联网上寻找解决方案,但一无所获。我正在尝试使我的iOS 5应用程序与iOS 6兼容。我不能让迎新的东西正常工作。我无法检测到何时会发生旋转。下面是我正在尝试的代码:
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
// pre-iOS 6 support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
新的supportedInterfaceOrientation:方法可以很好地调用。但是,shouldAutorotate方法不会触发。我需要在旋转时进行一些图像交换,但我无法获得任何旋转即将发生的迹象。
提前谢谢。
发布于 2013-05-08 16:27:34
当使用UINavigationController作为应用程序的基础时,我使用以下子类为我提供了灵活性,允许最顶层的子视图控制器决定旋转。
@interface RotationAwareNavigationController : UINavigationController
@end
@implementation RotationAwareNavigationController
-(NSUInteger)supportedInterfaceOrientations {
UIViewController *top = self.topViewController;
return top.supportedInterfaceOrientations;
}
-(BOOL)shouldAutorotate {
UIViewController *top = self.topViewController;
return [top shouldAutorotate];
}
@end
发布于 2014-04-20 21:54:44
我使用的是iOS 7,但我相信我的案例可能会对其他人有所帮助。
我有一个以UITabBarController为根的深层视图控制器层次结构。保证调用shouldAutorotate的唯一位置是在UITabBarController内部。因此,我简单地将UITabBarController子类化,并将旋转控制逻辑放入shouldAutorotate方法中。
发布于 2013-06-13 07:27:21
这就是我要做的
如果要检查哪个是当前方向,请将此行添加到viewconrtoller.m文件中
#define isPortrait [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown
然后在你想要检查方向的地方,像下面这样写条件
- (void)viewDidLoad
{
if(isPortrait)
{
//portrait mode....
NSLog(@"its in IsPotraitMode");
}
else
{
//landscape mode....
NSLog(@"its in IsLandscapeMode");
}
}
https://stackoverflow.com/questions/12775265
复制相似问题