Wrong screen size after dismissing UIImagePickerCo

2019-04-28 05:35发布

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 )

3条回答
戒情不戒烟
2楼-- · 2019-04-28 06:05

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

查看更多
疯言疯语
3楼-- · 2019-04-28 06:13

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.

查看更多
劳资没心,怎么记你
4楼-- · 2019-04-28 06:14

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

}
查看更多
登录 后发表回答