【问题标题】:Camera is not rotating properly in iOS8 beta for old projects旧项目的 iOS8 测试版中的相机无法正确旋转
【发布时间】:2014-09-28 03:22:42
【问题描述】:

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

以下是屏幕截图。

在横向模式下(正常工作):

在肖像模式下(一旦加载相机,我已经旋转它,这里其他控件旋转正常,但相机过度旋转不正常):

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

有什么解决办法吗?

提前致谢。

【问题讨论】:

  • 检查相机应用...可能是测试版的错误
  • 不,我还没有解决。 @Boni2k
  • 这里有同样的问题! - 接近投票:给出一个正确的代码示例相当困难,因为处理 iOS 应用轮换的部分相差甚远!
  • 我遇到了确切的问题。纵向启动时的奇怪行为,横向启动似乎没问题。
  • @Rufus 是的,“开始”方向工作正常。旋转它会使图片混乱。这甚至可以在一个非常基本的 UIImagePickerController 项目中重现。只有相机控件应该旋转,但预览本身不应该......

标签: objective-c uiimagepickercontroller ios8 uideviceorientation xcode6


【解决方案1】:

我也有同样的问题。
我尝试使用 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

它似乎工作
但源头并不漂亮……

【讨论】:

  • 我认为它会在 iOS 8.1 中修复
【解决方案2】:

已经发布了我认为是解决方案的内容,在; https://stackoverflow.com/a/26934067/782533

看起来同样的问题?不确定我是否应该链接或复制/粘贴,所以无论如何都在这里;

我遇到了同样的问题,在回归基础并创建了一个实际有效的新项目之后。我追踪到它;

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    // Had forgot to call the following..
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

希望对你有帮助。

【讨论】:

    【解决方案3】:

    根据this thread on Apple Dev forums iOS8/XCode6 中的旋转在使用XIBs 时会出现一些问题,而在使用Storyboards 时则不会。

    【讨论】:

      猜你喜欢
      • 2014-11-13
      • 1970-01-01
      • 2022-08-15
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多