为什么UITabBarController返回"..应该支持至少一个方向"的消息?

Dav*_*vid 3 iphone landscape uitabbarcontroller ios

我将UITabBarController子类化为了覆盖,shouldAutorotateToInterfaceOrientation:以便在某些情况下我可以支持横向模式.当我运行它时,标签栏控制器在重写方法返回时给我以下消息NO

The view controller <...0x644f50> returned NO from -shouldAutorotateToInterfaceOrientation: for all interface orientations. It should support at least one orientation.

如何回报比让其他消息的乘坐任何建议YES在所有的时间shouldAutorotateToInterfaceOrientation?

Emi*_*aez 13

如果返回NO,则表示视图控制器无法在4个方向中的任何一个上显示.

您应该考虑您希望它支持哪些方向,并使用orientation它们为您提供的参数来接受这些方向.

例如,如果我希望我的视图控制器支持纵向和横向,这将是我的实现(这可以简化为一行,但为了清晰起见我正在扩展它):

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIDeviceOrientation)orientation{
  if(orientation == UIDeviceOrientationPortrait) return YES;
  if(orientation == UIDeviceOrientationLandscapeRight) return YES;
  return NO;
}
Run Code Online (Sandbox Code Playgroud)