2010-01-13 55 views
2

我試着來檢測的UIImagePickerController(它的UINavigationController繼承:UIViewController中:UIResponder:NSObject的)方向變化,我試圖覆蓋UIViewController中,但沒有成功的方法- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation ...檢測UIImagePickerController中的方向更改?

任何提示?

在此先感謝...

回答

4

UIImagePickerController不支持子類化!

該類用於原樣使用,不支持子類。

也許你可以註冊UIDeviceOrientationDidChangeNotification from UIDevice並使用它?

+0

謝謝你!它對我很好! – 2010-01-13 17:11:12

+0

請注意,設備方向更改包含比界面方向更多的兩個常量(即:面朝上和麪朝下) - 您必須記住您擁有的最後一個方向(縱向/橫向),並忽略面朝上/向下的變化以知道哪個接口您的實際方向。 – 2010-01-13 17:14:05

+1

不幸的是,如果設備的方向被鎖定,則不再發布通知,但相機界面仍在更新。你有沒有找到解決辦法? – FelixLam 2012-01-09 18:25:28

0

從官方文檔的UIImagePickerController:

重要: UIImagePickerController類僅支持肖像模式。此類旨在按原樣使用,不支持子類。這個類的視圖層次是私有的,不能修改,只有一個例外。在iPhone OS 3.1及更高版本中,您可以將自定義視圖分配給cameraOverlayView屬性,並使用該視圖呈現附加信息或管理攝像頭界面和代碼之間的交互。

2

這是來不及回答在這裏,但我擴大@Adam WOS答案,

之前呈現UIImagePickerController

UIImagePickerController *controllerObject = [[UIImagePickerController alloc] init]; 
... 
... 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)name:UIDeviceOrientationDidChangeNotification object:nil]; 
... 
... 
[self presentViewController:controllerObject animated:YES completion:nil]; 

- (void)orientationChanged:(NSNotification *)notification{ 
    [self adjustViewsForOrientation:UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]]; 
} 

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation 
{ 
    if(orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) 
    { 
     NSLog(@".....landscape....."); 
    } 
    else if(orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) 
    { 
     NSLog(@".....portrait....."); 
    } 
} 

UIImagePickerController得到解僱不要忘了,

[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; 
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 

另請注意,根據@AdamWoś的@FelixLam評論回答,

如果設備方向已鎖定,則不會再發布通知。

爲了處理這種情況,一是需要實施CoreMotion(替代UIAccelerometer的iOS 6.0 <)來檢測設備的方向被鎖定或沒有。這裏的博客UIAccelerometerhttp://blog.sallarp.com/iphone-accelerometer-device-orientation/這是CoreMotionhttps://github.com/tastyone/MotionOrientation你必須踢一些邏輯來檢查這一點。

祝你好運!