在UIImagePickerController中强制横向
我是iOS开发的新手,并开发我的第一个应用程序。 (很抱歉,如果我问一个新手问题)
我的应用程序都是纵向的,除了我使用UIImagePickerController拍摄照片的地方,我正在做的是:
UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage]; picker.allowsEditing = NO; [self presentModalViewController:picker animated:YES];
由于我的应用程序是在肖像 ,我需要使UIImagePickerController只在景观 。 如果我尝试使用:
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
似乎我不能使用,因为我的Xcode识别为这一行中的错误(可能是因为Xcode的版本,我不知道)。 我不确定,但似乎如果我正在开发iOS 5.1,我将需要为iOS 6.0实施一些东西,这是否正确?
有人可以帮助我了解什么是需要使这个UIImagePickerController ,只有这个视图控制器在应用程序,工作在横向方向,并在iOS 5.1和6?
问候
根据UIImagePickerController类参考
重要提示 :
UIImagePickerController
类只支持纵向模式。 这个类的目的是按原样使用,不支持子类。 这个类的视图层次是私有的,不能修改,只有一个例外。 您可以将自定义视图分配给cameraOverlayView属性,并使用该视图呈现附加信息或pipe理摄像头界面和代码之间的交互。
所以看起来强制横向模式是不受支持和不鼓励的,除非通过用自定义cameraOverlayView
replace默认控件。
创build一个名为“CUIImagePickerController”的类inheritance自UIImagePickerController,重写下面的方法,现在使用这个类!
@interface CUIImagePickerController : UIImagePickerController @end @implementation CUIImagePickerController - (BOOL)shouldAutorotate { return NO; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient { return (orient == UIInterfaceOrientationLandscapeLeft) | (orient == UIInterfaceOrientationLandscapeRight); } @end
问候,
尝试执行下面的方法:
- (BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; }