在横向模式下打开UIImagePickerController

我想在我的应用程序中打开iphone保存的图像。 我的应用程序工作在横向模式。 当我试图从iPhone库中使用presentModalViewController方法加载所有保存的照片,它将以纵向模式打开。 我想在横向模式。 这里是代码:

picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; picker.allowsEditing = NO; picker.navigationBarHidden = YES; picker.wantsFullScreenLayout = YES; [picker setNavigationBarHidden:TRUE]; [self presentModalViewController:picker animated:NO]; NSLog(@"%@", self.view.subviews); [picker release]; 

可以任何一个帮助我..在此先感谢。

你不能。 记下文件 :

UIImagePickerController类只支持纵向模式。 这个类的目的是按原样使用,不支持子类。

这是一个更多的工作,但你可以使用AssetsLibrary框架来访问图像列表,并创build自己的图像select器。

我们不能在横向中获取UIImagePickerController …

但我们可以在我们的设备中的图像到一个数组,并显示在横向模式和纵向模式….它看起来像UIImagePickerController一样…

我们应该使用ALAsset类和ALAssetsLibrary这个..

 void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) { if(result != NULL) { [assets addObject:result]; } }; void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) { if(group != nil) { [group enumerateAssetsUsingBlock:assetEnumerator]; } [self meth]; [activity stopAnimating]; [activity setHidden:YES]; }; assets = [[NSMutableArray alloc] init]; ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:assetGroupEnumerator failureBlock: ^(NSError *error) { NSLog(@"Failure");}]; 

在viewDidLoad中

 -(void)meth { NSLog(@"%i",[assets count]); if(userOrientation==UIInterfaceOrientationPortrait || userOrientation==UIInterfaceOrientationPortraitUpsideDown) { NSLog(@"haii"); [scrollView removeFromSuperview]; scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)]; scrollView.backgroundColor=[UIColor whiteColor]; NSLog(@"%i",[assets count]); for (int i = 0; i < [assets count]; i++) { imgBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [imgBtn setFrame:CGRectMake((i%4*80)+2,(i/4*80)+2,75,75)]; imgBtn.tag=i; [imgBtn addTarget:self action:@selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside]; ALAsset *asset=[assets objectAtIndex:i]; [imgBtn setImage:[UIImage imageWithCGImage:[asset thumbnail]] forState:UIControlStateNormal]; [scrollView addSubview:imgBtn]; } scrollView.contentSize = CGSizeMake(320,(([assets count]/4)+1)*300 ); } if(userOrientation==UIInterfaceOrientationLandscapeRight || userOrientation==UIInterfaceOrientationLandscapeLeft) { [scrollView removeFromSuperview]; scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 480,320)]; for (int i = 0; i < [assets count]; i++) { imgBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [imgBtn setFrame:CGRectMake((i%6*80)+2,(i/6*80)+2,75,75)]; imgBtn.tag=i; [imgBtn addTarget:self action:@selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside]; ALAsset *asset=[assets objectAtIndex:i]; [imgBtn setImage:[UIImage imageWithCGImage:[asset thumbnail]] forState:UIControlStateNormal]; [scrollView addSubview:imgBtn]; } scrollView.contentSize = CGSizeMake(480,(([assets count]/4)+1)*300); } [self.view addSubview:scrollView]; } 

我已经尝试了一些补充的代码

 [self.navigationController setNavigationBarHidden:YES]; [self addChildViewController:picker]; [self.view addSubview:picker.view]; picker.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; picker.view.frame = self.view.bounds; [picker didMoveToParentViewController:self]; 

 (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; self.imageView.image = chosenImage; [picker.view removeFromSuperview]; [picker removeFromParentViewController]; } 

 (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker.view removeFromSuperview]; [picker removeFromParentViewController]; } 

我用下面的代码:

 [self.view addSubview:imgPicker.view]; [imgPicker viewWillAppear:YES]; [imgPicker viewDidAppear:YES]; 

而不是使用presentModalViewController方法, [self presentModalViewController:picker animated:NO] ;

我尝试了这种方法,同时更紧密地跟踪API文档:

 - (void)openEmbeddedImagePicker:(UIImagePickerController *)picker { [self.navigationController setNavigationBarHidden:YES]; [self addChildViewController:picker]; [self.view addSubview:picker.view]; picker.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; picker.view.frame = self.view.bounds; [picker didMoveToParentViewController:self]; } 

但录像机的取消和播放button不响应。 另外,当包含VC(上述方法中的self )限制风景的方向时,两个风景模式之间的旋转会混淆选取器覆盖栏的布局(至less在iOS 6上)。

有没有人有成功的限制录像机横向模式?

从UIImagePickerController类参考 。

重要提示: UIImagePickerController类只支持纵向模式。 这个类的目的是按原样使用,不支持子类。 这个类的视图层次是私有的,不能修改,只有一个例外。 您可以将自定义视图分配给cameraOverlayView属性,并使用该视图呈现附加信息或pipe理摄像头界面和代码之间的交互。