3

如何更改UIImagePickerControlleron的尺寸宽度iPad?我可以改变高度,所以它是 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];
4

3 回答 3

10

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

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

这将防止调整弹出框的大小。

于 2013-02-28T19:01:02.113 回答
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)];
于 2012-12-07T16:37:17.427 回答
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];
    }
于 2017-03-17T22:27:39.970 回答