How to add UIImagePickerController in UiView

2019-05-13 19:51发布

How to add UIImagePickerController in UiView in TabBarApplication

1条回答
别忘想泡老子
2楼-- · 2019-05-13 20:22

It doesn't matter if you are in a tab, this code goes into the ViewController class for your view

Create a picker when you want one

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
// configure it how you want

Add the picker

[self presentViewController:picker animated:YES completion:nil];

Your view controller needs to be declared like

@interface YourViewController :  
   UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>

And you need to implement

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

(the first one should get the image from the info object)

In each of those messages, when done, remove the picker

[self dismissModalViewControllerAnimated:YES];
查看更多
登录 后发表回答