UIImagePickerController when dismissed pushes view

2020-05-08 06:41发布

EDIT : I am using UIStoryBoard.

I have presented like this:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

imagePicker.delegate = self;

imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //| UIImagePickerControllerSourceTypeSavedPhotosAlbum ;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        imagePicker.allowsEditing = YES;
        [self.navigationController presentViewController:imagePicker animated:YES completion:^{

        }];  
    }
}

Now when dissmissed

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   UIImage *image = info[UIImagePickerControllerEditedImage];
    NSLog(@"Image : %@",image);
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

Now view becomes like this as shown in fiqure :

enter image description here

EDIT : view gets pushed up to 20px when dissmissed.

EDIT : This is only in iOS 6.0 only

4条回答
beautiful°
2楼-- · 2020-05-08 07:06

I had similar issue on iOS 8.2. After picking video using UIImagePickerController the frame is increased by 20px, top area of view controller is looking good, but the bottom is cut off. The solution is:

-(void)openPicker {}
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    //configure image picker here
    [self presentViewController:picker animated:YES completion:NULL];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(showStatusBar) userInfo:nil repeats:NO];
    [picker dismissViewControllerAnimated:YES completion:NULL];
}

-(void)showStatusBar {
    dispatch_async(dispatch_get_main_queue(), ^{
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
    });
}
查看更多
做个烂人
3楼-- · 2020-05-08 07:14

If that blue part of view is custom UIView then you should check the auto resizing mask for that view. You will find the problem.

查看更多
不美不萌又怎样
4楼-- · 2020-05-08 07:26

The reason was i was setting frame of view controller which is in protrait mode as its previous view was in landscape mode.

self.view.bounds = CGRectMake(0,0,...,...);

Whenever imagepicker dissmiss got called it moved to original position as mentioned.

Now changed in structure for orientation without setting self.view frame externally solved my problem.

查看更多
Fickle 薄情
5楼-- · 2020-05-08 07:27

I have similar problem, and in my case 20 pixels was the status bar height. So, try to set status bar visibility to NO before showing imagePicker and YES when it finished (in delegate methods).

something like this:

[UIApplication sharedApplication].statusBarHidden = YES;
[self.navigationController presentViewController:imagePicker animated:YES completion:^{
        }];


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   // ... your code here
   [UIApplication sharedApplication].statusBarHidden = NO;
   [self dismissViewControllerAnimated:YES completion:^{
    }];
}
查看更多
登录 后发表回答