I have a very simple application:
- All orientations are permitted with only a button on a screen
- The button show a UIImagePickerController
(to take a photo)
The issue has been fixed in iOS 8.1 Tested with Contacts App. works fine.
But another issue I found ,
Test it 2 3 times with FaceUp orientation, the camera view will start rotating strangely again as you can see in the Pictures uploaded above.
I got the same issue. I tested on both iOS 7.1.2 and iOS 8. So far, it only happened on iPad device with iOS 8. So I temporarily fix it by following code:
// In my app, I subclass UIImagePickerController and code my own control buttons
// showsCameraControls = NO;
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
}
It is not recommended because it will mess up the presentingViewController's orientation.
Are there any replies from Apple yet?
I found an easy and accurate patch to resolve this issue. Add following code before presenting UIImagePickerController:
if (iOS8_Device)
{
if([[UIDevice currentDevice]orientation] == UIDeviceOrientationFaceUp)
{
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
{
[[UIDevice currentDevice]setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeRight] forKey:@"orientation"];
}
else
{
[[UIDevice currentDevice]setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
}
}
}
Also you need to subclass UIImagePickerController and override following method as below to work it better.
- (BOOL)shouldAutorotate
{
[super shouldAutorotate];
return NO;
}
After using above code it will work for both landscape orientation well and the orientation will not be changed to UIDeviceOrientationFaceUp mode.
This is the code I used to fix my app that was rotating the openCV camera into landscape if the camera was started with the device on the desk in Face Up position. The camera needed to be forced into portrait mode for the app to function correctly.
- (BOOL)shouldAutorotate
{
[super shouldAutorotate];
return NO;
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear: animated];
if([[UIDevice currentDevice]orientation] == UIDeviceOrientationFaceUp)
{
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
{
[[UIDevice currentDevice]setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];
}
else
{
[[UIDevice currentDevice]setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];
}
}
}
I believe it is an iOS 8 bug. For example if you open your contacts app and click edit/add photo/take photo, the same issue occurs on a standard iOS app! Post the issue to Apple support just as I have.
As @hitme said, it is a bug in iOS 8, but you can work around the issue by setting -[UIImagePickerController cameraViewTransform]
before presenting it:
CGFloat angle;
switch (interfaceOrientation)
{
case UIInterfaceOrientationLandscapeLeft:
angle = M_PI_2;
break;
case UIInterfaceOrientationLandscapeRight:
angle = -M_PI_2;
break;
case UIInterfaceOrientationPortraitUpsideDown:
angle = M_PI;
break;
default:
angle = 0;
break;
}
imagePicker.cameraViewTransform = CGAffineTransformMakeRotation([UIApplication sharedApplication].statusBarOrientation);