相机叠加视图不会改变iPhone4的横向(左右)方向



我用覆盖视图自定义了相机的自定义按钮(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)中运行不佳。有人能帮我解决这个问题吗?

谢谢我的朋友。我已经自己解决了这个问题。我只是设置了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中也检查了这个条件。现在,我的应用程序工作魅力。谢谢。

最新更新