2017-05-02 67 views
1

我正在使用基本上在橫向模式下運行的遊戲。 它可以選擇更改Profile Pic。 配置文件圖片選項打開用於在配置文件圖片圖片視圖上顯示的圖片選擇器。 我的問題是應用程序在ios中更改方向時崩潰7

當圖像選擇器打開時,應用程序自動將方向改爲肖像。

爲了解決這個問題,我試過,當他點擊上傳圖片按鈕,然後選擇圖片後,我強行改變設備取向上一個捕獲用戶的方向。 一切工作正常在iPhone 5和更高版本。但是,當用戶從選擇器視圖中選擇圖像時,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上和更高但不是在iPhone 4在iOS 7.0.1

在此先感謝跑!

+0

[preferredInterfaceOrientationForPresentation必須返回支持的接口方向]的可能重複(http://stackoverflow.com/questions/12690963/preferredinterfaceorientationforpresentation-must-return-a-supported-interface-o) – Koen

回答

0

我會嘗試,目前發現的設備的方向,看看設備需要被迫轉動。你也可能需要在你的plist文件中添加縱向和橫向的信息,然後你不想自動旋轉任何屏幕,你可以添加一個方法來調用。

比如你caould在您的應用程序委託添加一個方法,像這樣用入店變量shouldAllowRotation:

-(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; 
} 

然而,如果你在一個導航控制器推視圖控制器到其他視圖控制器的堆棧,只要求景觀效果不佳。您應該以模態方式顯示風景約束視圖控制器。