OK, so I managed to figure it out. It should be noted that the UIImagePickerController class only supports portrait mode in accordance with the Apple documentation .
To capture rotation willRotateToInterfaceOrientation is useless here, so you need to use notificatons. In addition, setting autodetection restrictions at run time is not appropriate.
In AppDelegate didFinishLaunchingWithOptions you need to enable rotation notifications:
// send notification on rotation [[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];
In the viewDidLoad method of the OverlayView UIViewController add the following:
//add observer for the rotation notification [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
Finally, add the orientationChanged: method to the camera UIViewController
- (void)orientationChanged:(NSNotification *)notification { UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; double rotation = 0; switch (orientation) { case UIDeviceOrientationPortrait: rotation = 0; break; case UIDeviceOrientationPortraitUpsideDown: rotation = M_PI; break; case UIDeviceOrientationLandscapeLeft: rotation = M_PI_2; break; case UIDeviceOrientationLandscapeRight: rotation = -M_PI_2; break; case UIDeviceOrientationFaceDown: case UIDeviceOrientationFaceUp: case UIDeviceOrientationUnknown: default: return; } CGAffineTransform transform = CGAffineTransformMakeRotation(rotation); [UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ self.btnCancel.transform = transform; self.btnSnap.transform = transform; }completion:nil]; }
The above code applies the rotation conversion to 2 UIButtons, which I use btnCancel and btnSnap in this case. This gives you the effect of the Camera app while rotating the device. I still get a warning in the console <Error>: CGAffineTransformInvert: singular matrix. I donβt know why this is happening, but it has something to do with the camera view.
Hope this helps.
pechar
source share