4

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

这就是我实现应用程序的方式:我将 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,但它仍然旋转。

提前致谢。

4

4 回答 4

5

可以将覆盖视图添加到窗口中,然后可以将window.superview设置为cameraOverlayView。在关闭 ModalController 时,可以从窗口中删除覆盖视图。

根据您的应用程序的结构,此解决方案可能有点难以应用。

YourAppDelegate *appDelegate = (YourAppDelegate *) [[UIApplication sharedApplication] delegate];
[appDelegate.window addSubview:overlayView];
imagePickerController.cameraOverlayView = appDelegate.window.superview;


//When dismissing the UIImagePicker
 [self dismissModalViewControllerAnimated:YES];
 [OverlayView removeFromSuperview]; 
于 2011-04-25T14:37:15.650 回答
0

因为 UIImagePickerController 派生自 UINavigationController 派生自 UIViewController,所以您可以查看 UIViewController 文档中的“处理视图旋转”以查看该信息是否有帮助。

于 2011-04-18T08:50:26.233 回答
0

当你这样做时,你会注意到:

UIImagePickerController *camera = [UIImagePickerController new];
NSLog([self.camera shouldAutorotate] ? @"YES" : @"NO");

结果将是肯定的。我认为默认情况下,它设置为YES。

您可以继承 UIImagePickerController 并添加此方法来覆盖该方法:

- (BOOL)shouldAutorotate{
return NO;
}

然后,不要使用 UIImagePickerController,而是使用您创建的子类。

UIImagePickerSubclass *camera = [UIImagePickerSubclass new];

希望这可以帮助 :)

于 2013-11-26T03:48:31.180 回答
-3

您可以通过旋转 UIImagePickerController 的覆盖视图来补偿 ipad 的旋转。首先,您必须使用以下方法捕获通知:

[[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;
        }
    }
 }
}
于 2011-04-25T08:50:18.020 回答