0

我正在开发 iOS 6 应用程序,我使用以下方法处理了 UIview 旋转...

-(NSUInteger)supportedInterfaceOrientations

{
    return UIInterfaceOrientationMaskPortrait;
}


- (BOOL) shouldAutorotate {
    return YES;
}

一切正常,问题是初始视图加载是根据设备方向决定的,例如:如果我将设备保持在横向模式,即使我已在supportedInterfaceOrientations 中强制返回纵向视图,一旦设备旋转到肖像之后它不会进入横向模式,一切正常。无论设备方向如何,是否可以在特定模式下加载视图?

我用谷歌搜索,没有任何效果。

注意:我正在使用导航控制器。我为 UINavigationController 添加了类别。

// 在 IOS6 中处理方向的自定义类别

@implementation UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end

谢谢

4

1 回答 1

0

使用此方法:

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationMaskPortrait;
}

将此方法与categoryfor UINavigationControllerin一起添加appDelegate

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
  //check for which controller u need these methods
  if([navigationController.visibleViewController isKindOfClass:[yourViewController class]]) //provide specific view controller where u want protrait
  {
    [navigationController shouldAutorotate];
    [navigationController supportedInterfaceOrientations];
    [navigationController preferredInterfaceOrientationForPresentation];
  }
  return UIInterfaceOrientationMaskAll;
}

注意category:如果您添加了 for ,请从所有 viewController 中删除UINavigationController。它应该只在 appDelegate 中。

于 2013-01-03T11:54:04.310 回答