gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 18:34:49 24 4
gpt4 key购买 nike

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

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

此代码将相机覆盖 View 保持在横向模式下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;
}

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

最佳答案

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

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

关于iphone - 如何更改 iPhone 左右相机 Overlayview 方向横向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8356773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com