How to use UIImagePickerController in iPad?

后端 未结 4 982
太阳男子
太阳男子 2020-12-01 12:34

Hi i am working on a universal application (iPhone/iPad). one feature is that i have to select a photo from album and show it on UIImageView.

Now problem is that it

4条回答
  •  臣服心动
    2020-12-01 13:21

    UIImagePickerController must be presented with UIPopoverController on iPad.

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
        [popover presentPopoverFromRect:self.selectedImageView.bounds inView:self.selectedImageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        self.popOver = popover;
    } else {
        [self presentModalViewController:picker animated:YES];
    }
    

    EDIT: Add a strong property for the UIPopoverController:

    @property (nonatomic, strong) UIPopoverController *popOver;
    

    The popover should be dismissed in the delegate methods:

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

提交回复
热议问题