これは、iPhone4s/iOS5.1 および iPhone3G/iOS6.1 でテストされたクリーンな方法です。
私は Apple の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 メディア キャプチャを使用することです。これにより、(わずかに) 複雑さが増しますが、写真撮影プロセスをよりきめ細かく制御できます。