我有一个导航控制器:
//=========================
- (BOOL)shouldAutorotate;
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
NSLog(@"Nav: supported Orientation");
if ([[self topViewController] respondsToSelector:@selector(supportedInterfaceOrientations)])
else
return [super supportedInterfaceOrientations];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[self.topViewController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[self.topViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
MY ROOTCTRL:
//=========================
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}
-(BOOL)shouldAutorotate
{
return YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
NSString *risp;
switch (self.interfaceOrientation) {
case UIInterfaceOrientationLandscapeLeft:
risp = @"LAND_LEFT";
break;
case UIInterfaceOrientationLandscapeRight:
risp = @"LAND_RIGHT";
break;
case UIInterfaceOrientationPortrait:
risp = @"PORT";
break;
case UIInterfaceOrientationPortraitUpsideDown:
risp = @"PORT_UPsideDOWN";
break;
case UIInterfaceOrientationUnknown:
risp = @"UNKNOW";
break;
default:
break;
}
NSLog(@"HOME didRotate:%@",risp);
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
}
始终调用UINavigationController的supportedInterfaceOrientations ,也始终调用Home Controller的 supportedInterfaceOrientations ;但是Home不会从LANDSCAPE LEFT旋转到LANDSCAPE RIGHT,反之亦然:
所以Home ctrl在启动时有正确的方向,但是如果设备确实旋转了Home控制器从不旋转......它只被称为supportedInterfaceOrientations方法(导航控制器和根控制器),没有任何效果......
我做错了什么?
答案 0 :(得分:1)
如果在iOS8上运行并且您的代码自iOS8之前就已存在,请检查以下答案。删除应用委托中提到的行(如果存在),它应该开始工作。