Incorrect screen size after rejecting UIImagePickerController

I have an iOS application such as whatsapp and ... when I present a UIImagePickerController with a source type of UIImagePickerControllerSourceTypeCamera .

 imagePicker = [UIImagePickerController new]; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.delegate = self; imagePicker.mediaTypes =[NSArray arrayWithObjects:(NSString *)kUTTypeMovie,(NSString *)kUTTypeImage,nil]; [self presentViewController:imagePicker animated:YES completion:nil]; 

Problem

Several times after canceling or completing the capture of the UIImagePickerController in Video mode, when I return to my view manager (turn off the camera), my View input (my Windows) goes to the bottom with 20 pixels (status bar height), I think my problem is related to this link How to set the view under the green bar during a phone call? , because in the video segment the status indicator is displayed for several minutes. In some conditions, my Windows (UITabbar in the previous controller goes to the bottom as well) !!!

enter image description here

Edit

the solution only works in its current form, but another view controller is damaged (goes down)

+6
source share
3 answers

Finally fiexed

Special thanks to danialzahid94.

To fix this problem you should call

 [self dismissViewControllerAnimated:YES completion:^{ self.view.frame = [[UIScreen mainScreen]bounds]; [self.view layoutIfNeeded]; self.tabBarController.view.frame = [[UIScreen mainScreen]bounds]; [self.tabBarController.view layoutIfNeeded]; // for fixing tabbar Controller }]; 

in 2 delegate:

- (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker - (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info

+3
source

If you use automatic layout, you can try self.view.layoutIfNeeded() when the UIImagePickerController rejected. If this does not work, you can get the screen size and assign it self.view.frame as follows:

 self.view.frame = UIScreen.mainScreen().bounds 

This usually works for me.

+1
source

When I applied the @Mohamad solution after updating the frame, when I clicked on textView, it showed an empty black area above the keyboard, and when I returned from the controller, Tabbar moved down, so I implemented the code below a permanent solution .

 @property CGRect viewFrame; @property CGRect tabbarFrame; - (void)viewWillAppear:(BOOL)animated { if (CGRectIsEmpty(self.viewFrame)) { self.viewFrame=self.view.frame; self.tabbarFrame=self.tabBarController.view.frame; } } - (void)viewDidAppear:(BOOL)animated { [self correctScreenSize]; } -(void)correctScreenSize { self.view.frame = self.viewFrame; [self.view layoutIfNeeded]; self.tabBarController.view.frame = self.tabbarFrame; [self.tabBarController.view layoutIfNeeded]; } 
0
source

All Articles