UIImagePickerController camera view rotating strangely on iOS 8 (pictures)

后端 未结 12 1482
我寻月下人不归
我寻月下人不归 2020-12-07 16:34

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)

12条回答
  •  星月不相逢
    2020-12-07 17:20

    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.

提交回复
热议问题