如何在iPad上更改UIImagePickerController的大小宽度?

时间:2012-12-07 15:57:56

标签: objective-c ios ipad uiimagepickercontroller uipopovercontroller

如何更改UIImagePickerControlleriPad的尺寸宽度?我可以改变高度,所以它是700但不能改变宽度,它仍然是320。 我的代码。

 UIImagePickerController*  imagePicker=[[UIImagePickerController alloc]init];
 imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
 imagePicker.delegate=self;
 CGRect myRect = CGRectMake(imagePicker.view.frame.origin.x, imagePicker.view.frame.origin.y, 720, 700);
 imagePicker.view.frame = myRect;
 self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
 myRect = CGRectMake(100, 880, 900, 900);
 CGRect re2 = CGRectMake(0,0,800,800);
 [self.popover setPopoverContentSize:re2.size];
 [self.popover presentPopoverFromRect:[self.view bounds] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
 [self.popover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];      
 [self.popover setPopoverContentSize:re2.size];

3 个答案:

答案 0 :(得分:10)

我遇到了同样的问题,我用UINavigationControllerDelegate解决了,因为PhotoLibrary的UIImagePickerView内容是一个navigatorController。当您选择一行时,它会更改ViewController,并且弹出窗口的大小也会更改。 所以,在你的willShowViewController委托中只需输入:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    viewController.contentSizeForViewInPopover = CGSizeMake(800, 800);
}

这样可以防止弹出窗口的大小调整。

答案 1 :(得分:3)

这个简化的代码对我来说很好:

    UIImagePickerController*  imagePicker=[[UIImagePickerController alloc]init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
    [self.popover presentPopoverFromRect:CGRectMake(100, 880, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    [self.popover setPopoverContentSize:CGSizeMake(700, 700)];

答案 2 :(得分:1)

iOS 9及以上版本。

另一种方法是使用 ContainerViewController 并将UImagePickerViewController添加到ContainerViewController。 UINavigationControllerDelegate方法中的覆盖大小有其局限性。 (不可能在高于600pt的高度下降)

    _imagePicker                      = [[UIImagePickerController alloc] init];
    _imagePicker.delegate             = self;
    _imagePicker.sourceType           = UIImagePickerControllerSourceTypeCamera;
    _imagePicker.preferredContentSize = CGSizeMake(320, 480);

    UIViewController *containerViewController    = [[UIViewController alloc] init];
    containerViewController.preferredContentSize = _imagePicker.preferredContentSize;
    [containerViewController addChildViewController:_imagePicker];
    [containerViewController.view addSubview:_imagePicker.view];
    [_imagePicker didMoveToParentViewController:containerViewController];

    if (!_imagePickerPopover) {
        //customize PopoverController, use your own
        _imagePickerPopover = [[PopoverController alloc] init:cnt];
    }