应用程序在iOS 7中的变化方向崩溃



我正在使用基本上在景观模式下运行的游戏。它具有更改个人资料图片的选择。Profile PIC选项打开用于在配置文件图片视图上显示的图像选择器。我的问题是

打开图像选择器时,该应用会自动将方向更改为肖像。

为了解决此问题,我在单击上传图像按钮时尝试捕获用户的方向,然后选择图像后,我将强制将设备方向更改为上一个。在iPhone 5和更高版本上,一切正常。但是,当用户从Picker View选择图像时,iPhone 4(在iOS7上运行(会崩溃。我遇到以下错误 -

preferredinterfaceorientationforpresentation必须返回支持的接口方向!

我正在使用此代码检查用户的方向

-(void)checkCurrentDeviceOrientation
{
if([UIDevice currentDevice].orientation == 
UIDeviceOrientationLandscapeRight || [UIDevice 
currentDevice].orientation == UIDeviceOrientationLandscapeLeft )
{
self.currentOrientation = [UIDevice currentDevice].orientation;
}
else
{
self.currentOrientation = UIDeviceOrientationLandscapeRight;
}
}

并使用此代码设置方向。

 if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8"))
 {
 if([UIDevice currentDevice].orientation == 
UIDeviceOrientationPortrait ||[UIDevice currentDevice].orientation == 
UIDeviceOrientationPortraitUpsideDown  )
 {
    NSLog(@"Chnaging Device Orientation to stored orientation");
    NSNumber *value = [NSNumber numberWithInt:self.currentOrientation];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
}
else
{
//Code For IPHONE 4
}

希望在iOS8上和更高的iOS8上一切正常,但在iOSS 4上运行的iOS 7.0.1

不正常。

预先感谢!

我将尝试找到当前的设备方向,并查看是否需要强制旋转设备。您可能还需要在PLIST文件中添加肖像和景观能力,然后您不想自动旋转的任何屏幕都可以添加一种方法来调用。

例如,您在应用程序委托中添加类似的方法,并具有ACCIBLE变量应遵守:

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if(self.shouldAllowRotation)
        return UIInterfaceOrientationMaskAll;
    else
        return UIInterfaceOrientationMaskPortrait;
}

然后在每个视图中您可以调用

[[AppDelegate instance] setShouldAllowRotation:NO];

取决于是否应该旋转。当调用采摘器时,只需打电话给应用程序委托,然后自动旋转,这将使您获得

- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}

但是,如果将视图控制器推到导航控制器中的其他视图控制器上,则仅需要景观就无法正常工作。您应该模态显示景观构成视图控制器。

最新更新