2013-05-08 113 views
1

我已經閱讀了幾乎所有關於我的問題的文章,但沒有一個解決方案似乎適用於我的應用。在iOS 6.1中自定義自定義相機視圖

因此,我使用自定義的相機視圖(帶有工具欄和覆蓋圖上的按鈕),這是從視圖控制器以模態方式呈現的。我的應用只支持橫向左右方向。我想在自動旋轉時停止相機視圖。我已經將所有自動旋轉所需的方法放到了我的視圖控制器和我的應用程序委託中。我也檢查過我的plist文件,支持的旋轉是正確的。但是當我旋轉設備時,我的相機視圖會一直旋轉到任何旋轉(縱向和橫向),導致覆蓋層和工具欄被錯誤定位。我也無法檢查相機視圖的方向,因爲我試圖把NSLog放在shouldAutoRotate方法上,但它根本不會被調用。

那麼如何檢查自定義相機視圖上的旋轉?我該如何強迫它不旋轉並保持靜止?

如果我的代碼是需要的,我會在這裏發佈。如果任何人都可以幫助我,我會非常感激,因爲它現在讓我非常失望。

謝謝。乾杯。

+0

您的項目有導航控制器? – 2013-05-08 04:31:12

+0

是的,我使用導航控制器 – tyegah123 2013-05-08 04:45:04

+0

好吧,我認爲現在唯一的解決方法就是使用iPad本身的按鈕來鎖定自動旋轉。 – tyegah123 2013-05-08 05:19:24

回答

2

創建一個新類的「 UIImagePickerController「並執行.m文件中的旋轉代表,如下所示:

// For lower iOS versions 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 

return ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || ((toInterfaceOrientation == UIInterfaceOrientationLandscapeRight))); 
} 

// For iOS version 6.0 and above 
- (BOOL)shouldAutorotate { 

return YES; 
} 


- (NSUInteger)supportedInterfaceOrientations { 

return (UIInterfaceOrientationMaskLandscape); 
} 

並讓一個實例讓我們說MyImagePickerController而不是UIImagePickerController,並呈現它。這將工作:)

+0

謝謝你的回答。我現在正在嘗試這個,我會讓你知道它是否工作:) – tyegah123 2013-05-08 07:44:00

+0

男人,非常感謝你。它運作良好。已經接受你的答案。 :) – tyegah123 2013-05-08 07:49:10

+0

歡迎:) – 2013-05-08 09:11:32

0

創建類別的UINavigationController

@interface UINavigationController(autoRotation) 

-(BOOL)shouldAutoRotate; 

@end 

@implementation UINavigationController 

-(BOOL)shouldAutoRotate{ 

    return [[self.viewControllers lastobject] shouldAutoRoatate]; 

} 

-(NSUInteger)supportedInterfaceOrientations { 

    return [[self.viewControllers lastobject] supportedInterfaceOrientations]; 

} 

@end 

在相應的視圖控制器 實現這兩個方法,並返回什麼ü真正想要的方向....

+0

謝謝您的回答。但我也已經嘗試過這種方法。沒有給我我想要的結果。但也許我錯過了一些東西。所以,也許我會嘗試更多的這種方法。 – tyegah123 2013-05-08 05:54:21

+0

你如何帶上你的相機?使用presentModalViewController?如果是,您的UIImagePickerViewController不存在於導航堆棧中。所以你必須爲你的IMagePickerViewController創建一個類別並且調用shouldAutoRotae ... – jailani 2013-05-08 06:16:56

+0

是的,我正在使用presentModalViewController。你能給我示例代碼來創建類別嗎?我一定會嘗試一下,因爲它看起來像是這樣。 – tyegah123 2013-05-08 07:37:34

0

的Xcode - >文件 - >在leftpane新文件選擇cocotouch選擇的Objective-C類 - >未來 從下拉式

進口

給出名稱選擇器類UIImageImagePickerController

@interface的UIImagePickerController(拾取器)

- (BOOL)shouldAutoRotate; - (NSUInteger)supportedInterfaceOrientations;

@end

進口「的UIImagePickerController +選擇器。H」

@implementation的UIImagePickerController(拾取器)

- (BOOL)shouldAutoRotate {

return yourOrientation; 

}

- (NSUInteger)supportedInterfaceOrientations {

return yourInteger; 

}

@end

這時候你的設備的方向則改變了方法shouldAutoRotate獲得從此時您的UINavigationController類叫你必須找出是否cameraview提出,如果是,那麼你必須調用選擇器

的shouldAutoRotate後

請看下面的代碼

在您的視圖控制器的shouldAutoRotate

- (BOOL)shouldAutoRotate {

if([self presentingViewController])// Camera is present 
     return [instanceOfUIImagePickerController shouldAutoRotate]; 
    return yourOrientaionNeededForThisVC; 

}