objective-c - 对于旧项目,相机在 iOS8 beta 中不能正确旋转

标签 objective-c uiimagepickercontroller ios8 uideviceorientation xcode6

我正在开发一个使用旧版 X 代码创建的 iOS 应用程序,因此它在 MainWindow.xib 中有窗口。 最近在 iOS8 Beta 版本中运行这个项目时,遇到了一个问题:窗口没有横向旋转。所以我在 MainWindow.xib 中添加了另一个窗口。我做了 if 条件来检查操作系统版本,对于旧的 iOS 版本,我使用以前创建的窗口,但对于 iOS8,我使用新添加的横向窗口。我已经解决了这个问题。除了相机,整个应用程序都正常工作。

下面是屏幕截图。

在横向模式下(正常工作): enter image description here

在PortraitMode中(加载相机后,我旋转了它,这里其他控件旋转正常,但相机过度旋转不正确):

enter image description here

在横向模式下加载相机后,我旋转了设备,控件正确旋转但相机屏幕不旋转,它仍处于纵向模式。 这可能是由于 Appdelegate 中的窗口。

有什么解决办法吗?

提前致谢。

最佳答案

我遇到了同样的问题。
我尝试使用 cameraViewTransform。

下方

#import "MyUIImagePickerController.h"

@implementation MyUIImagePickerController

bool rotateFlg = false;
UIInterfaceOrientation startupOrientation;

-(id)init{
    startupOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    return [super init];
}

-(NSUInteger)supportedInterfaceOrientations {
    // iOS 8
    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
        float lotate[4];
        if (startupOrientation == UIInterfaceOrientationLandscapeRight || startupOrientation == UIInterfaceOrientationLandscapeLeft) {
            lotate[0] = 90.0f;
            lotate[1] = -90.0f;
            lotate[2] = 180.0f;
            lotate[3] = 0.0f;
        } else {
            lotate[0] = 0.0f;
            lotate[1] = 180.0f;
            lotate[2] = 90.0f;
            lotate[3] = -90.0f;
        }

        UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
        if(orientation ==UIInterfaceOrientationPortrait ){
            CGAffineTransform __rotation = CGAffineTransformMakeRotation(lotate[0] * M_PI / 180.0f);
            self.cameraViewTransform = __rotation;
            rotateFlg = true;
        }
        else if(orientation == UIInterfaceOrientationPortraitUpsideDown){
            CGAffineTransform __rotation = CGAffineTransformMakeRotation(lotate[1] * M_PI / 180.0f);

            self.cameraViewTransform = __rotation;
            rotateFlg = true;
        } else if(orientation == UIInterfaceOrientationLandscapeLeft){
            if (rotateFlg) {
                CGAffineTransform __rotation = CGAffineTransformMakeRotation(lotate[2] * M_PI / 180.0f);
                self.cameraViewTransform = __rotation;
                rotateFlg = false;
            }
        }else if(orientation == UIInterfaceOrientationLandscapeRight){
            if (rotateFlg) {
                CGAffineTransform __rotation = CGAffineTransformMakeRotation(lotate[3] * M_PI / 180.0f);
                self.cameraViewTransform = __rotation;
                rotateFlg = false;
            }
        }
    }
    return UIInterfaceOrientationMaskAll;
}
@end

这似乎有效
但是源码不美...

关于objective-c - 对于旧项目,相机在 iOS8 beta 中不能正确旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25139246/

相关文章:

ios - 如何将搜索栏制作成 iPhone 联系人应用程序或处理多个不完整关键字的搜索栏

iphone - 保持对 IOS AddressBook 条目的长期引用

ios - 如何获取从 UIimagePicker 中获取的视频的大小?

ios - 在服务器上自动备份照片的最佳方法?

ios - 将它用于 UIImageView 时 UIImage 失真

core-data - 将自定义类保存到核心数据

ios - 如何支持 iOs 9 功能,同时保持对 iOs 8 的支持?

ios - 键盘尺寸更大

objective-c - UIImagePickerController 在 iOS 8 中没有正确呈现

iOS UIImagePickerController 和 ModalViewController