3

如何更改UIImagePickerController的尺寸寬度iPad?我可以改變高度,所以它是700,但不能改變寬度,它仍然是320. 我的代碼。如何在iPad上更改UIImagePickerController的大小寬度?

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]; 
+0

爲什麼要從兩個不同的rects提交兩次popover?另外,不需要設置imagePicker的框架,因爲它是彈出窗口的內容視圖控制器,並且在設置彈出窗口contentSize時將設置其大小。 – rdelmar

回答

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)]; 
+0

問題似乎是,只要選擇一行,大小就會變回320.這就好像imagePicker已經爲iPhone設計。 – Srikanth

+0

@Srikanth,你應該編輯你的問題來增加這個事實 - 這與你發佈的問題不同。 – rdelmar

10

我有你同樣的問題,我解決了與UINavigationControllerDelegate,因爲UIImagePickerView內容的PhotoLibrary是navigatorController。當你選擇一行時,它會改變ViewController,彈窗的大小也會改變。 所以,在你willShowViewController代表只是把:

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

這將防止酥料餅的大小調整。

+0

非常感謝。 –

+0

嗨。我使用你的代碼來解決調整大小的問題。解決了。但是現在,當我嘗試選擇圖像時,它的標籤位置錯位。當我在其右側的一個圖像上標籤時,下一張圖像被錄製和選擇。請幫忙.. – Durgaprasad

0

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]; 
    } 
相關問題