UIImagePicker Black Bar on iPad - Landscape Only

I am showing UIImagePicker (myself in UIView) through UIPopOver. This works great, however, when the iPad is rotated to the right side, I get a strange black bar along the left side of the popcorn as shown below. The cancel button is also partially located on the right side of the screen. This does not happen in any other orientation that is odd.

The code is also listed below. Can anyone guess why I get this black bar?

imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; CGFloat width = CGRectGetWidth(self.view.bounds); CGFloat height = CGRectGetHeight(self.view.bounds); UIViewController *containerController = [[UIViewController alloc] init]; containerController.contentSizeForViewInPopover = CGSizeMake(width, height); [imagePickerController.view setFrame:containerController.view.frame]; [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]; [containerController release]; } 

Screen shot

+1
source share
3 answers

For some strange reason, the view frame changes the landscape to the right.

To understand this, set the frame after that you represent the popover (see code below).

That should do the trick.

 imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; CGFloat width = CGRectGetWidth(self.view.bounds); CGFloat height = CGRectGetHeight(self.view.bounds); UIViewController *containerController = [[UIViewController alloc] init]; containerController.contentSizeForViewInPopover = CGSizeMake(width, height); [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]; [containerController release]; } 

Also, in your controller, add this to the reset frames during rotation:

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

The above approach works with iOS 5 and above, but on iOS 4 and before it's impossible to add a UIImagePickerController as a subtitle and then show it. It should always be represented as a ModalViewController.

+1
source

Try it. Transferring one solution that I found using [currentDevice endGeneratingDeviceOrientationNotifications]

 UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease]; picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.delegate = self; // Display the camera. [self presentModalViewController:picker animated:YES]; // Given by default your orientation is in landscape right already while ([currentDevice isGeneratingDeviceOrientationNotifications]) [currentDevice endGeneratingDeviceOrientationNotifications]; 

Source: Disable rotation in UIImagePicker

-1
source

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


All Articles