如何更改 iPhone 左右相机 Overlayview 方向横向?

发布于 2024-12-19 03:05:10 字数 1341 浏览 1 评论 0原文

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

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

,此代码将相机覆盖视图保持在横向模式右侧 GAffineTransform 变换 = 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;
    }

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

In my iPhone application i have a UIImagePickerController for take photos. I have hide all default camera controls and added UIView with Two button as a CameraOverLayView in UIImagePickerController. My application is always run in Landscape mode only. The Camera is also launching Landscape mode only. Now, the CameraOverlayView is only in Landscape Left side not change to Landscape to Right. How can i change the CameraOverlayView LandscapeMode Left and Right when the device orientation will changing? Please help me to fix it. It is major problem in my app. This code hold the Overlayview in Landscape mode Left

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

and this code hold the cameraoverlayview in Landscape mode right
GAffineTransform transform = self.view.transform;

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

    imgpicker.cameraOverlayView.transform = transform;

I used these codes in UIInterfaceOrientation methods like this,

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

But, these are not helping me. When i rotate the device orientation landscape left and right, the cameraoverlayview does not changing. Can you please fix my problem? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终弃我 2024-12-26 03:05:10

感谢大家。我自己解决了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);
        }  
}

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

Thanks to all. I have solved the Camera OverlayView orientation problem by myself. I have used the same code mentioned in my question. Just i have added UIDeviceOrientation Notification for the orientation changes. Please find the code below,

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

I just added this method additionally in my code. So that when the user change the device orientation this method will call and change camera overlay view's orientation. Please check your conditions inside this method otherwise app will getting crash. Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文