2014-05-06 40 views
0

我有一個處於橫向模式的應用程序。iPhone/iPad中的方向問題

該應用程序專爲iPhone和iPad設計。

我正在打開照片庫,從那裏訪問照片,並從我的一些視圖中捕捉照片。

但據我所知,照片庫只能在肖像模式下打開,所以我從下面顯示的設置中選擇所有的方向。

enter image description here

我也做了同樣的事情iPad也。

所以我嘗試從所有視圖的代碼。

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 
-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight ; 
} 

因此,所有的視圖只能在肖像模式下鎖定。

但我的看法仍然顯示在肖像模式也。

對於圖片庫,我做了一個不同的類,如下所示。

@interface NonRotatingUIImagePickerController8 : UIImagePickerController 

@end 

@implementation NonRotatingUIImagePickerController 



- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationPortrait ; 
} 

@end 



@interface NonRotatingUIImagePickerController2 : UIImagePickerController 

@end 

@implementation NonRotatingUIImagePickerController2 

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 

@end 

因此,我的照片庫以縱向模式顯示,但我的所有其他視圖以縱向模式顯示。

那麼我該如何解決這個問題?

請幫幫我。

卡住了很長一段時間。

在此先感謝....

**Edited** 

enter image description here

如果我做這樣我的應用充分說明在風景模式,但是當我嘗試打開照片庫崩潰。

我該怎麼做?

請幫忙....

+0

所以我的照片庫中顯示POTRAIT模式但我的所有其他視圖以POTRAIT模式顯示。你什麼意思?錯字?如果可以的話,上傳一個示例項目到Github並鏈接到這裏,有人可以爲你解決這個問題。 – Ricky

+0

如果我沒有從我的項目設置中選擇肖像,如圖中所示,那麼我的應用程序將崩潰,因爲照片庫只能在iPhone的肖像模式下打開... – Manthan

+0

self.view.transform = CGAffineTransformMakeRotation(M_PI_2) ;在你的照片庫視圖中使用 –

回答

1

我也遇到過這種情況,我找到了解決辦法,看看我下面的代碼。

首先評論您在每個班級中編寫的所有方向方法。

然後對號所有orientaition像下面

enter image description here

現在

在AppDelegate中。下面的代碼在「呈現」 M文件寫入是的UIViewController在你試圖打開pickerview

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    NSUInteger orientations = UIInterfaceOrientationMaskAll; 

    if (self.window.rootViewController) { 
     UIViewController* presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject]; 
     if([presented isKindOfClass:[PhotoVC class]]) 
     { 
      orientations = [presented supportedInterfaceOrientations]; 
      return orientations; 
     } 
     orientations = UIInterfaceOrientationMaskLandscape; 
    } 
    return orientations; 
} 

現在我的代碼替換代碼在你NonRotatingUIImagePickerController2像下面

@interface NonRotatingUIImagePickerController2 : UIImagePickerController 

@end 

@implementation NonRotatingUIImagePickerController2 

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskLandscape; 
} 


@end 

請檢查並讓我知道它工作與否!

快樂編碼!在方向下拉

打開你的故事板,選擇視圖控制器,然後選擇「風景」:

+0

因爲NavigationController的問題? – Manthan

+0

沒有問題不是因爲NavigationController,你錯過了我的朋友,你是否從所有的視圖控制器中刪除所有的方向代碼? – NiravPatel

+0

是的,我做了,但我發現了另一個解決方案https://github.com/B-Sides/ELCImagePickerController/tree/master/Classes/ELCImagePicker,它以橫向模式打開ImagePicker。非常感謝您的幫助,直到現在。我將保留你的代碼並將其用於將來的項目,因爲現在我正在對舊項目進行更改,所以問題就在於此,因爲我對前一個開發人員的代碼沒有多少了解。我只是對現有項目進行一些修改。 – Manthan