8

I have an iOS app like whatsapp & ... when I present UIImagePickerController with UIImagePickerControllerSourceTypeCamera source type.

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

Some times after cancel or finish capturing UIImagePickerController in Video mode , when I back to my viewController (dismiss camera ) my input View (my Windows) going to bottom with 20 pixel ( status bar height ), I think my problem relate to this link How to position view below green bar during phone call? , because in video segment a recording status bar show for a few moment. In some condition my Windows (UITabbar in previous controller going to bottom as same ) !!!

enter image description here

Edit

the solution works only in current View but another View controller corrupt ( going to bottom )

Community
  • 1
  • 1
Mo Farhand
  • 1,144
  • 8
  • 21

3 Answers3

5

Finally it's Fiexed

special thanks to danialzahid94.

for Fix this issue , 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

Mo Farhand
  • 1,144
  • 8
  • 21
1

If you are using auto layout, you could try self.view.layoutIfNeeded() when the UIImagePickerController dismisses. If that doesn't work, you can get the screen size and assign it to your self.view.frame like this:

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

This usually works for me.

danialzahid94
  • 4,103
  • 2
  • 19
  • 31
  • my project is Auto Layout . i will try it at this time . let me to notify about this. i want to say a little note: after dismiss camera ( a little status bar recording with Red color appear for a second ( like call status bar ) , i think it cause this problem. – Mo Farhand Sep 09 '15 at 06:40
  • should i call self.view.layoutIfNeeded() -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker dismissViewControllerAnimated:YES completion:^{ [self.view layoutIfNeeded]; }]; OR out of this block ? – Mo Farhand Sep 09 '15 at 06:43
  • Yes, you will call it in that block. Do add the `self.view.frame = [[UIScreen mainScreen] bounds]` before calling `layoutIfNeeded` – danialzahid94 Sep 09 '15 at 06:50
  • i think only self.view.frame = [[UIScreen mainScreen] bounds enough , let me to notify about final result :) – Mo Farhand Sep 09 '15 at 06:52
  • Also add those two lines in `imagePickerController:didFinishPickingMediaWithInfo:` delegate method if you have implemented it. The same way as you have added in `didCancel:` – danialzahid94 Sep 09 '15 at 06:52
  • yes , sure bro , i add these 2 lines in imagePickerController:didFinishPickingMediaWithInfo: as the same – Mo Farhand Sep 09 '15 at 06:53
  • i added only self.view.frame = UIScreen.mainScreen().bounds in compleation of block . should i call LayoutIfNeeded ? in some condition , our current viewController is ok as well but the parent of my ViewController ( in UINavigationController ) corrupt :( – Mo Farhand Sep 09 '15 at 07:00
  • 1
    You should add layoutIfNeeded as well – danialzahid94 Sep 09 '15 at 07:14
  • we are testing the application , everything works fine in this view controller (which we named it second view controller) . but I have another problem in the total view hierarchy . when the UIimage picker dismissed the previous view controllers ' frame changed . view hierarchy----> tabbarcontroller - navigation controller - first viewcontroller . I mean the first view controller frame has problem now does it need to add another navigation controller before second view controller? – Mo Farhand Sep 09 '15 at 07:34
  • the solution works only in current View but another View controller corrupt ( going to bottom ) – Mo Farhand Sep 09 '15 at 08:14
0

When I applied the @Mohamad Solution after updating the frame when I tapped on the textView its was showing blank black area above the keyboard and when I returned back from the controller Tabbar shifted down so I implemented the Below code is 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];

}
Pandey_Laxman
  • 3,889
  • 2
  • 21
  • 39