UIImagePickerController(使用相机作为源)在iPad2上会自动旋转,如何停止它? [英] UIImagePickerController (using camera as source) does autorotate on iPad2, how do i stop it?

查看:174
本文介绍了UIImagePickerController(使用相机作为源)在iPad2上会自动旋转,如何停止它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写具有某些摄像头功能的应用程序,并使用叠加视图用图像装饰它.

I am trying to write an app with some camera function, and I use an overlay view to decorate it with an image.

这是我实施该应用程序的方式: 我使用UIImagePickerController来向谁吸引相机用户,并将UIImageView作为子视图添加到cameraOverlayView上,以便它像这样工作:
(图像位于 http://www.manna-soft.com/test/uploads/UIImagePickerView-portrait.jpg )

This is how I implement the app: I use the UIImagePickerController to who the user what the camera takes in, and add a UIImageView onto the cameraOverlayView as a subview so that it works like this:
(image at http://www.manna-soft.com/test/uploads/UIImagePickerView-portrait.jpg)

在iPad2放到位之前,它可以正常工作……它会像这样自动旋转并破坏布局:
(图像位于 http://www.manna-soft.com/test/uploads/UIImagePickerView-landscape.jpg )

This works fine until the iPad2 come into place... it autorotates like this and ruin the layout:
(image at http://www.manna-soft.com/test/uploads/UIImagePickerView-landscape.jpg)

UIImagePickerController从不在iphone,ipod touch或原始iPad上旋转,但在iPad2上旋转. UIImagePickerContrller的类引用说它仅支持纵向模式",但是发生的是它会像这样自动旋转....
有什么方法可以禁用自动旋转吗?
我尝试在呈现UIImagePickerController的视图控制器的shouldAutorotateToInterfaceOrientation:方法中返回NO,但该控件仍会旋转.

The UIImagePickerController never rotates on iphone, ipod touch or the original iPad, but it does on iPad2. the class reference of UIImagePickerContrller says that it "supports portrait mode only", but what happens is it autorotates like that....
Is there a way that I can disable the autorotation?
I tried returning NO in the method shouldAutorotateToInterfaceOrientation: of the view controller which the UIImagePickerController is presented, but it still rotates.

谢谢.

推荐答案

您可以通过设置UIImagePickerController的叠加视图的轮廓来补偿ipad的旋转.首先,您必须使用以下命令捕获通知:

You can compensate the rotation of your ipad by roatting the overlay view of your UIImagePickerController. Fisrt you have to capture the notifications using:

[[NSNotificationCenter defaultCenter]     addObserver:self selector:@selector(notificationCallback:) name:nil object:nil];

然后使用此代码:

 - (void) notificationCallback:(NSNotification *) notification {
  if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    if ([[notification name] isEqualToString:@"UIDeviceOrientationDidChangeNotification"]) { 

        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

        switch ( orientation ) {
            case UIInterfaceOrientationLandscapeRight:
                NSLog(@"LandcapeRight");
                [UIView beginAnimations:@"LandscapeRight" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformIdentity;
                [UIView commitAnimations];
                break;
            case UIInterfaceOrientationLandscapeLeft:
                NSLog(@"LandscapeLeft");
                [UIView beginAnimations:@"LandcapeLeft" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(M_PI), 0, 0);
                [UIView commitAnimations];
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                NSLog(@"UpsideDown");
                [UIView beginAnimations:@"UpsideDown" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(-M_PI / 2), -128, -128);
                [UIView commitAnimations];
                break;
            case UIInterfaceOrientationPortrait:
                NSLog(@"Portrait");
                [UIView beginAnimations:@"Portrait" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(M_PI / 2), 128, 128);
                [UIView commitAnimations];
                break;
            default:
                NSLog(@"????");
                break;
        }
    }
 }
}

这篇关于UIImagePickerController(使用相机作为源)在iPad2上会自动旋转,如何停止它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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