如何更改iPhone左右侧的摄像头覆盖视图方向?
在我的iPhone应用程序中,我有一个用于拍照的UIImagePickerController。我隐藏了所有默认的相机控件,并在UIImagePickerController中添加了带有两个按钮的UIView作为CameraOverLayView。我的应用程序始终仅在横向模式下运行。相机也仅启动横向模式。现在,CameraOverlayView只显示在横向左侧,而不会更改为横向右侧。当设备方向发生变化时,如何左右更改CameraOverlayView景观模式?请帮我修一下。这是我的应用程序中的主要问题。此代码将覆盖视图保持在横向模式左侧如何更改iPhone左右侧的摄像头覆盖视图方向?,iphone,orientation,landscape,camera-overlay,Iphone,Orientation,Landscape,Camera Overlay,在我的iPhone应用程序中,我有一个用于拍照的UIImagePickerController。我隐藏了所有默认的相机控件,并在UIImagePickerController中添加了带有两个按钮的UIView作为CameraOverLayView。我的应用程序始终仅在横向模式下运行。相机也仅启动横向模式。现在,CameraOverlayView只显示在横向左侧,而不会更改为横向右侧。当设备方向发生变化时,如何左右更改CameraOverlayView景观模式?请帮我修一下。这是我的应用程序中的主
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不会改变。你能解决我的问题吗?谢谢。谢谢大家。我已经自己解决了相机覆盖视图方向的问题。我使用了问题中提到的相同代码。我刚刚为方向更改添加了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);
}
}
我刚刚在代码中添加了这个方法。因此,当用户更改设备方向时,此方法将调用并更改摄影机覆盖视图的方向。请检查此方法中的条件,否则应用程序将崩溃。谢谢。有人解决了这个问题吗?谢谢你,伙计@JayQ:你解决了这个问题吗?@SamBudda:你解决了这个问题吗?我正在使用这个,我的覆盖层从来没有正确排列过。它总是太左或太右。@yuvaraj:嗨……我在用iPhone4,你能告诉我方向的准确旋转代码吗。我可以旋转它,但是按钮是左对齐还是右对齐。@yourfriendzak:你找到解决办法了吗?如果是这样,你能帮我吗?