简体   繁体   English

访问相机和照片库错误

[英]Accessing camera and photo library error

 //In AppDelegate.m, I am forcing every window to LandScapeRight.

  -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskLandscapeRight;
   }

 //In ScanViewController.m, I am accessing camera and Image Library.

  @implementation ScanViewController
 -(void)viewDidLoad {
 [super viewDidLoad];
// Do any additional setup after loading the view.
 }
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }

- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
 }
//Select photo from iPhone Image Library.
- (IBAction)photoFromAlbum:(id)sender 
 {
UIImagePickerController *photoPicker = [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
photoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:photoPicker animated:YES completion:NULL];
 }
//Take photo from camera
- (IBAction)photoFromCamera:(id)sender 
 {
UIImagePickerController *photoPicker = [[UIImagePickerController alloc] init]; 
photoPicker.delegate = self;
photoPicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
[self presentViewController:photoPicker animated:YES completion:NULL];
 }
//Save the Image
- (void)imagePickerController:(UIImagePickerController *)photoPicker    didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.saveButton.enabled = YES;
self.filterButton.enabled = YES;
originalImage = [info valueForKey:UIImagePickerControllerOriginalImage];
[self.selectedImageView setImage:originalImage];
[self dismissViewControllerAnimated:YES completion:nil];
}

Now, I am getting this error "PLUICameraViewController shouldAutorotate is returning YES". 现在,我收到此错误“ PLUICameraViewController shouldAutorotate返回YES”。 I am using iOS 8 and I want my application to work in landscape mode, but when I access "ScanViewController.m", then it can be both Landscape or portrait because I read that in iOS8, it is compulsory, when accessing camera to have portrait view. 我正在使用iOS 8,并且希望我的应用程序在横向模式下工作,但是当我访问“ ScanViewController.m”时,它可以是横向或纵向,因为我在iOS8中读到它是强制性的,访问摄像头时必须纵向视图。 Any suggestions are more than welcome. 任何建议都值得欢迎。

UICameraViewController only supports portrait mode. UICameraViewController仅支持纵向模式。 From the Apple Documentation: 从Apple文档中:

IMPORTANT 重要

The UIImagePickerController class supports portrait mode only. UIImagePickerController类仅支持纵向模式。 This class is intended to be used as-is and does not support subclassing. 该类旨在按原样使用,不支持子类化。 The view hierarchy for this class is private and must not be modified, with one exception. 此类的视图层次结构是私有的,除了一个例外,不得修改。 You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code. 您可以将自定义视图分配给cameraOverlayView属性,并使用该视图显示其他信息或管理摄像头界面与您的代码之间的交互。

So you should return UIInterfaceOrientationMaskPortrait on supportedInterfaceOrientations and you should also return NO on shouldAutorotate. 因此,您应该在supportedInterfaceOrientations上返回UIInterfaceOrientationMaskPortrait,并且还应该在shouldAutorotate上返回NO。

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM