0

我通过叠加视图使用自定义按钮(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) 中运行良好。谁能帮我解决这个问题?

4

1 回答 1

2

谢谢我的朋友们。我已经自己解决了这个问题。我只是将边界设置为 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 中检查了这种情况。现在,我的应用程序运行魅力。谢谢。

于 2012-01-19T06:19:37.613 回答