title: iPad iOS7 - UIImagePickerController in UIPopoverController has wrong preview image
body: <p>I am using an UIImagePickerController within an UIPopoverController which is working perfectly with iOS6. With iOS 7 the "preview" image which is shown to capture the image is rotated, but if I take a picture it is saved correctly.</p>
  
  <p>This is how I get my picker:</p>
  
  <pre><code>UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
  imagePicker.delegate = self;
  imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
  imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                (NSString *) kUTTypeImage,
                                nil];
  imagePicker.allowsEditing = NO;
  </code></pre>
  
  <p>And add it to a popover controller:</p>
  
  <pre><code>self.imagePickerPopOver = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
      [self.imagePickerPopOver presentPopoverFromRect:CGRectMake(aPosViewA.x, cameraButton_y, 100.0, 30.0) inView:self.detailViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  </code></pre>
  
  <p>Those are calculations for the button position at a UIScrollView to show the popover at the correct position:</p>
  
  <pre><code>presentPopoverFromRect:CGRectMake(aPosViewA.x, cameraButton_y, 100.0, 30.0)
  </code></pre>
  
  <p>I don't think that the problem lies there as I have tried out several combinations.</p>
  
  <p>I have also tried to capture the image in fullscreen-mode, but the app is only allowed to use landscape mode. If the image is taken in portrait-mode and the modal view is dismissed, the app stays in portrait mode as well. I couldn't find a way to prevent the UIImagePickerController to switch to portrait mode or to force the app back to landscape mode if the modal view was dismissed.</p>
  
  <p>UPDATE</p>
  
  <p>I have taken the answer from <a href="https://stackoverflow.com/questions/15563614/not-able-to-show-the-image-in-proper-format-from-camera-in-landscape-mode?lq=1">here</a> and came a step further.</p>
  
  <p>I transform the view after creating the picker and before showing the popover :</p>
  
  <pre><code>switch ([UIApplication sharedApplication].statusBarOrientation) {
          case UIInterfaceOrientationLandscapeLeft:
              self.imagePicker.view.transform = CGAffineTransformMakeRotation(M_PI/2);
              break;
          case UIInterfaceOrientationLandscapeRight:
              self.imagePicker.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
              break;
          default:
              break;
      }
  </code></pre>
  
  <p>which works as long as i don't turn around the iPad. For that I am registering for the orientation changed event: </p>
  
  <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification  object:nil];
  </code></pre>
  
  <p>and change the picker view:</p>
  
  <pre><code>- (void)orientationChanged:(NSNotification *)notification{
  
      if (self.imagePicker) {
          switch ([UIApplication sharedApplication].statusBarOrientation) {
              case UIInterfaceOrientationLandscapeLeft:
                  self.imagePicker.view.transform = CGAffineTransformMakeRotation(M_PI/2);
                  break;
              case UIInterfaceOrientationLandscapeRight:
                  self.imagePicker.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
                  break;
              default:
                  break;
          }
      }
  }
  </code></pre>
  
  <p>REMAINING PROBLEM:
  As I wrote in the beginning, when the picture was taken, it was shown correctly to accept or dismiss it. This is now transformed as well. Somehow I need to know when the image is taken and transform it back.</p>
  
  <p>AND, this is really a nasty hack and probably won't work with the next iOS Update. Has anybody an idea how to implement that in a cleaner way?</p>
  
  <p>UPDATE 2</p>
  
  <p>This was too nasty, I have found a cleaner solution which solves my problem but is not the answer to the initial question regarding an imagepicker in a popover controller, which is not recommended by Apple, but allowed.</p>
  
  <p>I have subclassed now the UIImagePickerController like this:</p>
  
  <pre><code>@implementation QPImagePickerController
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
      return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
  }
  
  - (BOOL)shouldAutorotate {
      return YES;
  }
  
  - (NSUInteger)supportedInterfaceOrientations{
      return UIInterfaceOrientationMaskLandscape;
  }
  
  @end
  </code></pre>
  
  <p>and I am using the imagepicker in fullscreen instead in a popover. Tested so far in iOS7.</p>