这里是一个干净的方式来做到这一点,上的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,而不是使用(稍微)更复杂的代价来更好地控制图片获取过程。
谢谢 - 看起来不错。我会测试一下。 –