objective-c – UIImagePickerController(使用相机作为源代码)在iPad2上进行自动旋转,我该怎么做呢?

我正在尝试使用一些相机功能编写应用程序,并使用叠加视图来装饰图像.

这是我实现应用程序的方式:
我使用UIImagePickerController来向用户提供相机所使用的内容,并将UIImageView作为子视图添加到cameraOverlayView上,以便它像这样工作:
(图片在http://www.manna-soft.com/test/uploads/UIImagePickerView-portrait.jpg)

这种方法很好,直到iPad2到位……它会像这样自动旋转并破坏布局:
(图片于http://www.manna-soft.com/test/uploads/UIImagePickerView-landscape.jpg)

UIImagePickerController永远不会在iphone,ipod touch或原始iPad上旋转,但它在iPad2上运行.
UIImagePickerContrller的类引用说它“仅支持肖像模式”,但是会发生什么呢?它会像那样自动旋转….
有没有办法可以禁用自动旋转?
我尝试在UIImagePickerController呈现的视图控制器的方法shouldAutorotateToInterfaceOrientation中返回NO,但它仍然会旋转.

提前致谢.

最佳答案 您可以通过掠夺UIImagePickerController的叠加视图来补偿ipad的旋转. Fisrt你必须使用以下方法捕获通知:

[[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;
        }
    }
 }
}
点赞