在我的iPhone应用程序中,我有一个用于拍照的UIImagePickerController。我隐藏了所有默认的相机控件,并在UIImagePickerController中添加了带有两个按钮的UIView作为CameraOverLayView。我的应用程序始终只在横向模式下运行。相机也仅启动横向模式。现在,CameraOverlayView仅在Landscape左侧不变为Landscape to Right。当设备方向改变时,如何左右更改CameraOverlayView LandscapeMode?请帮我修理一下。这是我的应用程序中的主要问题。此代码在横向模式中保持Overlayview Left
imgpicker.cameraOverlayView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, 117.81);
并且此代码将相机覆盖视图保持在横向模式中 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;
}
但是,这些并没有帮助我。当我左右旋转设备方向横向时,相机覆盖视图不会改变。你能解决我的问题吗?感谢。
答案 0 :(得分:16)
感谢所有人。我自己解决了Camera OverlayView方向问题。我使用了我的问题中提到的相同代码。我已经为方向更改添加了UIDeviceOrientation Notification。请找到以下代码,
[[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);
}
}
我刚刚在我的代码中添加了此方法。因此,当用户更改设备方向时,此方法将调用并更改相机覆盖视图的方向。请检查此方法中的条件,否则应用程序将崩溃。感谢。