這裏是一個乾淨的方式來做到這一點,上的iPhone4s/iOS5.1和iPhone3G的/ iOS6.1
測試我使用蘋果的PhotoPicker樣本,使一對夫婦的小變化。我希望你可以爲你的項目調整這種方法。基本的想法是每次旋轉時使用通知來觸發一個方法。如果該方法位於疊加層的視圖控制器中,則可以在imagePicker顯示時繼續操作疊加層。
在OverlayViewController.m
添加到initWithNibName
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(didChangeOrientation)
name:@"UIDeviceOrientationDidChangeNotification"
object:nil];
這些通知繼續,而pickerController被示出將被髮送這一點。所以在這裏,在覆蓋的視圖控制器,你可以繼續使用界面播放,例如:
- (void) didChangeOrientation
{
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
self.cancelButton.image =[UIImage imageNamed:@"portait_image.png"];
} else {
self.cancelButton.image =[UIImage imageNamed:@"landscape_image.png"];
}
}
你需要殺死通知並刪除viewDidUnload
觀察者:
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self];
注這個應用程序的設計方式:overlayViewController的行爲就像一個imagePickerController的包裝。所以,你通過的overlayViewController調用imagePicker :
[self presentModalViewController:self.overlayViewController.imagePickerController animated:YES];
的overlayViewController充當委託imagePickerController,並且反過來又委託方法傳遞信息返回到調用視圖控制器。
另一種方法是根本不使用UIImagePickerController,而是使用AVFoundation media capture,而不是使用(稍微)更復雜的代價來更好地控制圖片獲取過程。
謝謝 - 看起來不錯。我會測試一下。 –