自定义相机旋转问题 [英] Custom Camera Rotation problems

查看:140
本文介绍了自定义相机旋转问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义相机叠加层,像所有相机视图一样,在横向模式下是默认的。我有一些方向变化逻辑,检测方向的变化,所以我可以旋转我放置的按钮和视图。此外,我编辑了shouldAutoRotateInterfaceTo方法,所以它不会旋转相机打开时:

I have a custom camera overlay that, like all camera views, is default in landscape mode. I have some orientation change logic that detect when the orientation changes so I can rotate the buttons and views that I have placed. Also, I have edited the shouldAutoRotateInterfaceTo method so it does not rotate while the camera is on:

- (BOOL)shouldAutorotateToInterfaceOrientation
               (UIInterfaceOrientation)interfaceOrientation  {
        if (cameraIsOn) {
            return NO;
        }
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

问题:相机视图仍旋转为Portrait模式,当我将相机倾斜到风景。

Problem: the camera view still rotates into Portrait mode when I tilt the camera into Landscape. This results in the device being in Landscape position while the view is in Portrait, running off of the screen.

如果有帮助,这里是我用来检测方向的方法更改和转换我的按钮:

If it helps, here is the method I use to detect orientation changes and transform my buttons:

- (void)cameraOrientationChanged  {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
CGAffineTransform transform;
switch (orientation) {
    case UIDeviceOrientationPortrait:
        transform = CGAffineTransformIdentity;
        self.rotatePrompt.hidden = NO;
        break;
    case UIDeviceOrientationPortraitUpsideDown:
        //transform = CGAffineTransformMakeRotation(180*M_PI/180);
        transform = CGAffineTransformIdentity;
        self.rotatePrompt.hidden = NO;
        break;
    case UIDeviceOrientationLandscapeLeft:
        //transform = CGAffineTransformMakeRotation(90*M_PI/180);
        self.rotatePrompt.hidden = YES;
        transform = CGAffineTransformIdentity;
        break;
    case UIDeviceOrientationLandscapeRight:
        //transform = CGAffineTransformMakeRotation(-90.0*M_PI/180);
        transform = CGAffineTransformMakeRotation(180*M_PI/180);
        self.rotatePrompt.hidden = YES;
        break;
    default:
        transform = CGAffineTransformIdentity;
        break;
}
self.shootButton.transform = transform;
self.cameraTypeButton.transform = transform;
self.photoLibraryButton.transform = transform;
self.changeCameraDirectionButton.transform = transform;
self.flashButton.transform = transform;
self.videoTimerLabel.transform = transform;
self.closeCameraButton.transform = transform;

}

/ strong>这似乎是在我升级到iOS 5之前工作确定。

Note This seemed to be working ok before I upgraded to iOS 5.

更多信息
通过查看我的XIB文件,我可以看到,我在人像模式下创建了叠加。当相机重叠旋转时,当设备正在横向位置时,设备正在进入Portrait模式。

More Info By looking at my Xib file, I can see that I created the overlay in Portrait mode. When the camera overlay rotates it is moving into Portrait mode while the device is being help in Landscape position.

更奇怪的是,每当发生这种情况,我注意到shouldAutorotateToInderfaceOrientation没有在视图控制器中调用。

Even more peculiar, whenever this happens (it does not always happen), I noticed that shouldAutorotateToInderfaceOrientation is not being called in the view controller. I bet that has something to do with the problem here.

推荐答案

问题出在我的导航控制器设置。 UIImagePickerController将旋转消息发送到根视图控制器的shouldAutoRotateToInterface:方法。但是,由于我从一个旧项目(iOS 3)复制类,它没有自动复制shouldAutoRotateToInterface:方法。现在我在我的根视图控制器中写了方法,旋转问题是固定的。

The problem is with my navigation controller setup. UIImagePickerController sends the rotation message to the root view controller's shouldAutoRotateToInterface: method. However, since I copied the class from an older project (iOS 3), it did not have the shouldAutoRotateToInterface: method automatically copied. Now that I wrote the method in my root view controller, to rotation problem is fixed.

这篇关于自定义相机旋转问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆