7

我有一个仅在某些部分(照片库、视频等)支持横向方向的应用程序,并且在 iOS 6 上一切正常,没有问题,但是在 iOS 7 中应用程序崩溃。

所以这是我的问题:

  1. 启动应用程序并使用仅支持纵向的视图控制器加载初始导航控制器
  2. 将视图控制器推送到支持横向和纵向的堆栈
  3. 将视图旋转到横向
  4. 弹出视图控制器
  5. 应用程序崩溃
-->
CRASH: **preferredInterfaceOrientationForPresentation must return a supported interface orientation!**
2013-11-06 10:18:06.220 ausopen-iphone-2014[57605:70b] Stack Trace: (
  0   CoreFoundation                      0x03f665e4 __exceptionPreprocess + 180
  1   libobjc.A.dylib                     0x03ce38b6 objc_exception_throw + 44
  2   CoreFoundation                      0x03f663bb +[NSException raise:format:] + 139
  3   UIKit                               0x01366f1c -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:]

+ 580

其他信息:

在我的 info.plist 中,我支持纵向和横向

在我的 AppDelegate 中,我实现了以下方法:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{}

在这个方法中,我指定如果第一个视图 (HomeVC) 显示它应该支持所有方向。

在这个方法中,我还指定如果第二个视图 (PhotoVC) 显示它也应该支持所有方向。

在我的第一个视图(HomeVC)中,我使用以下方法覆盖了此方法,以便在显示视图时仅支持纵向模式:

- (BOOL)shouldAutorotate {
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
} 

不确定 iOS 7 在这方面发生了什么变化,因为在 iOS 6 中一切正常。似乎在 iOS 7 中,一旦弹出横向视图,应用程序就不会自动旋转回来。

任何帮助,将不胜感激..

4

2 回答 2

14

在IOS7中,如果使用UINavigationController,则旋转处理方式不同!

看UINavigationController,可以看出它是UIViewController的一个子类,那么就是在他里面有上面列出的旋转的处理方法;所以我需要使用 UINavigationController 也做旋转处理,

我的方法是向 UINavigationController 添加一个类别,这样做。

在类别中。米写

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {    
  return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
}
于 2013-11-29T10:15:16.393 回答
1

你可以简单地使用这个:-

-(void)rotateCameraView
{
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
}

//Mohit 18 Oct
- (void)deviceOrientationDidChange:(NSNotification *)notification {
    //Obtaining the current device orientation
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

    //Ignoring specific orientations
    if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown || orientation == UIDeviceOrientationUnknown) {
        return;
    }

    if ((UIDeviceOrientationIsPortrait(orientation) ||UIDeviceOrientationIsPortrait(orientation)) ||
    (UIDeviceOrientationIsLandscape(orientation) || UIDeviceOrientationIsLandscape(orientation))) {
        //still saving the current orientation
        currentOrientation = orientation;
    }
    [self performSelector:@selector(orientationChangedMethod) withObject:nil afterDelay:0];
}

//Mohit 18 Oct
    -(void)orientationChangedMethod
    {
        switch (currentOrientation) {

            case UIDeviceOrientationPortrait:
       }
    }


//Note here current orientation is a UIDeviceOrientation currentOrientation; global variable.
于 2013-11-07T08:42:15.387 回答