8

在我的 iPhone 应用程序中,我有一个 UIImagePickerController 用于拍照。我隐藏了所有默认的相机控件,并在 UIImagePickerController 中添加了带有两个按钮的 UIView 作为 CameraOverLayView。我的应用程序始终仅在横向模式下运行。相机也仅启动横向模式。现在,CameraOverlayView 仅在横向左侧,不会更改为横向到右侧。当设备方向发生变化时,如何左右更改 CameraOverlayView LandscapeMode?请帮我修复它。这是我的应用程序中的主要问题。此代码以横向模式保持 Overlayview 左

imgpicker.cameraOverlayView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, 117.81);

这段代码在横向模式下保持cameraoverlayview GAffineTransform transform = self.view.transform;

    transform = CGAffineTransformRotate(transform, (M_PI / 2.0));

    imgpicker.cameraOverlayView.transform = transform;

我在这样的 UIInterfaceOrientation 方法中使用了这些代码,

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;
    }

但是,这些对我没有帮助。当我左右旋转设备方向横向时,cameraoverlayview 不会改变。你能解决我的问题吗?谢谢。

4

1 回答 1

16

谢谢大家。我自己解决了 Camera OverlayView 方向问题。我使用了我的问题中提到的相同代码。只是我为方向更改添加了 UIDeviceOrientation 通知。请在下面找到代码,

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];


- (void) orientationChanged:(NSNotification *)notification
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if(orientation == UIDeviceOrientationLandscapeLeft)
        {                  
            CGAffineTransform transform = self.view.transform;
            transform = CGAffineTransformRotate(transform, (M_PI/2.0));
            imgpicker.cameraOverlayView.transform = transform;
        } 
        else if(orientation == UIDeviceOrientationLandscapeRight) 
        {   
            imgpicker.cameraOverlayView.transform = CGAffineTransformRotate(CGAffineTransformIdentity,117.81);
        }  
}

我刚刚在我的代码中添加了这个方法。因此,当用户更改设备方向时,此方法将调用并更改相机覆盖视图的方向。请在此方法中检查您的条件,否则应用程序将崩溃。谢谢。

于 2012-01-19T06:14:00.077 回答