這是來不及回答在這裏,但我擴大@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 <)來檢測設備的方向被鎖定或沒有。這裏的博客UIAccelerometer
http://blog.sallarp.com/iphone-accelerometer-device-orientation/這是CoreMotion
https://github.com/tastyone/MotionOrientation你必須踢一些邏輯來檢查這一點。
祝你好運!
謝謝你!它對我很好! – 2010-01-13 17:11:12
請注意,設備方向更改包含比界面方向更多的兩個常量(即:面朝上和麪朝下) - 您必須記住您擁有的最後一個方向(縱向/橫向),並忽略面朝上/向下的變化以知道哪個接口您的實際方向。 – 2010-01-13 17:14:05
不幸的是,如果設備的方向被鎖定,則不再發布通知,但相機界面仍在更新。你有沒有找到解決辦法? – FelixLam 2012-01-09 18:25:28