如何防止模式UIImagePickerController旋转?

我有一个完全支持轮换的应用程序。 我在模式上添加一个UIImagePickerController不支持,我不能让控制器留在肖像。

换句话说,我需要禁用旋转的UIImagePickerController所以它保持肖像,而不会删除我的应用程序的其余部分的旋转。 这似乎是基本的,但我似乎无法find它。 我怎样才能防止这种轮换?

UPDATE

正如所build议的,我试着用下面的代码进行子类化:

 @interface UAImagePickerController : UIImagePickerController { } @end @implementation UAImagePickerController - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return UIDeviceOrientationIsPortrait(toInterfaceOrientation); } @end 

该行没有被击中所有断点…我认为必须有一些关于UIImagePickerView

子类UIImagePickerController并有新的类实现shouldAutorotateToInterfaceOrientation:使其只能旋转到肖像,如下所示:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } 

我创build了我的UIImagePickerController在一个UIViewController里面,实现了相应的shouldAutorotateToInterfaceOrientation方法,并且像这样

 [self.view addSubview:myImagePicker.view]; [targetVC.navigationController presentModalViewController:self animated:YES]; 

希望有所帮助。

您应该重写_isSupportedInterfaceOrientation:,而不是shouldAutorotateToInterfaceOrientation:

iPad 2的UIImagePickerController相机自动旋转让我疯狂!

只要将它放在ViewControllers @implementation块的上面(在.m文件中)

 @implementation UIImagePickerController (portrait) - (BOOL)_isSupportedInterfaceOrientation:(UIDeviceOrientation)orientation { return UIDeviceOrientationIsPortrait(orientation); } @end