【问题标题】:Camera overlayview not change landscape orientation(Left and Right) in iPhone4?相机覆盖视图不会改变 iPhone 4 中的横向(左右)?
【发布时间】:2011-12-07 04:32:38
【问题描述】:

我已经通过覆盖视图自定义了带有自定义按钮(UIButton)的相机。我的 iPhone 应用程序只能在横向模式(左右)下运行。现在,我的相机叠加视图在 iPhone 3GS 中左右完美地改变了它的方向,但在 iPhone4 中运行不清晰。在 ios5 中,如果我在横向模式(右/左)下使用覆盖视图启动相机,它会完美启动,但是,如果我将方向更改为(右 -> 左/左 -> 右),则覆盖视图不会完全改变帧大小UIView(CameraOverlayView),UIButton 框架大小正在改变。我该如何解决?请帮我解决这个问题。我希望你我的朋友解决我的问题。提前致谢。在这里我附上了我使用的代码。

  UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

if(orientation == UIDeviceOrientationLandscapeLeft)
{
    CGAffineTransform transform = self.view.transform;
    transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
    imgpicker.cameraOverlayView.transform = transform;
    NSLog(@"Orientation Landscape Left");
} 
else if(orientation == UIDeviceOrientationLandscapeRight)
{
    imgpicker.cameraOverlayView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, 117.81);
    NSLog(@"Orientation Landscape Right");
}

此代码在 iPhone#GS(ios4) 中运行良好,但在 iPhone4(ios5) 中运行不佳。谁能帮我解决这个问题?

【问题讨论】:

    标签: iphone orientation landscape camera-overlay


    【解决方案1】:

    谢谢我的朋友们。我已经自己解决了这个问题。我只是将边界设置为 UIView,因此它涵盖了 Camera OverlayView 的完整视图,并且我已经尝试了我在问题中提到的上述代码。

         cameraview.bounds = CGRectMake(0.0, 0.0, 480.0f, 320.0f); 
    

    所以我在相机启动时检查了这段代码,

    UIInterfaceOrientation orientation= [[UIApplication sharedApplication] statusBarOrientation];
        if (orientation == UIInterfaceOrientationLandscapeLeft) 
        {
            imgpicker.cameraOverlayView.transform = CGAffineTransformRotate(CGAffineTransformIdentity,117.81);
        }
        else if (orientation == UIInterfaceOrientationLandscapeRight)
        {        
            CGAffineTransform transform = self.view.transform;
            transform = CGAffineTransformRotate(transform, (M_PI/2.0));
            imgpicker.cameraOverlayView.transform = transform;
        } 
    

    在此之后,我也在 UIDeviceOrientation Notification 中检查了这种情况。现在,我的应用程序运行魅力。谢谢。

    【讨论】:

    • 我创建了一个自定义相机,并且实时屏幕在纵向模式下加载良好。但是当我将其更改为横向模式时,我在控制台“CGAffineTransformInvert:奇异矩阵”中收到此错误。我尝试使用自动调整蒙版来更改实时屏幕的方向,但没有帮助。
    • 嗨......我已经修复了方向,我也面临着你之前面临的同样问题。你能帮我解决我的问题吗?
    猜你喜欢
    • 1970-01-01
    • 2016-06-08
    • 2013-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多