Resize UIImagePicker submitted via UIPopOver (iPad)

I am trying to resize the UIImagePicker that I represent through UIPopOver. The code is shown below. The problem is that the size of the PopOver does not display properly - it briefly flashes at the correct size, and then animates to the normal default size.

Can someone advise me how can I resize a popover?

- (void)showImagePickerForPhotoLibrary { NSLog(@"Picker"); imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePickerController.contentSizeForViewInPopover = CGSizeMake(768, 1000); if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { Class cls = NSClassFromString(@"UIPopoverController"); if (cls != nil) { popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController]; //popoverController.popoverContentSize = CGSizeMake(768, 1000); [popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES]; } } else { [app.mainViewController presentModalViewController:imagePickerController animated:YES]; } } 
+4
source share
2 answers

I'm not sure if this is the most elegant solution, but it seems to work fine for me:

You can embed the UIImagePickerController view in the container view of the UIViewController.

 - (void)showImagePickerForPhotoLibrary { NSLog(@"Picker"); imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; UIViewController *containerController = [[UIViewController alloc] init]; containerController.contentSizeForViewInPopover = CGSizeMake(768, 1000); [containerController.view addSubview:imagePickerController.view]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { Class cls = NSClassFromString(@"UIPopoverController"); if (cls != nil) { popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController]; [popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES]; [imagePickerController.view setFrame:containerController.view.frame]; } } else { [app.mainViewController presentModalViewController:containerController animated:YES]; } } 

Hope this helps

EDIT: for some strange reason, the frame really changes when it is in the right landscape.

To understand this, you need to set the image picker view frame after the popover view.

I changed the code above to show this.

Also, in your controller add the following:

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [imagePickerController.view setFrame:imagePickerController.view.superview.frame]; } 
+10
source

When I tried the Mutix solution, the popover showed only a navigation bar with an empty white view.

My way around it was to add imagePickerController as a child of the containerController, and not just add a selection view.

This basically means replacing this line:

 [containerController.view addSubview:imagePickerController.view]; 

with these lines:

 [containerController addChildViewController:imagePickerController]; [containerController.view addSubview:imagePickerController.view]; [imagePickerController didMoveToParentViewController:containerController]; 

In addition, when using this approach, I do not need special processing for landscape mode.

0
source

Source: https://habr.com/ru/post/1385143/


All Articles