(13)发送微博调用相机里面的图片以及调用相机
最后更新于:2022-04-01 07:27:21
## 一:效果
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-20_569f1d9a56914.jpg)
## 二:代码
相机部分就简单多了,几行代码调用而已,但是如果你要是想实现更多丰富的功能,需要自己写。利用AssetsLibrary.framework,利用这个框架可以获得手机上的所有相册图片,写一个图片选择控制器。
~~~
- (void)openCamera
{
[self openImagePickerController:UIImagePickerControllerSourceTypeCamera];
}
- (void)openAlbum
{
// 如果想自己写一个图片选择控制器,得利用AssetsLibrary.framework,利用这个框架可以获得手机上的所有相册图片
// UIImagePickerControllerSourceTypePhotoLibrary > UIImagePickerControllerSourceTypeSavedPhotosAlbum
[self openImagePickerController:UIImagePickerControllerSourceTypePhotoLibrary];
}
- (void)openImagePickerController:(UIImagePickerControllerSourceType)type
{
if (![UIImagePickerController isSourceTypeAvailable:type]) return;
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = type;
ipc.delegate = self;
[self presentViewController:ipc animated:YES completion:nil];
}
~~~
实现代理
~~~
#pragma mark - UIImagePickerControllerDelegate
/**
* 从UIImagePickerController选择完图片后就调用(拍照完毕或者选择相册图片完毕)
*/
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
// info中就包含了选择的图片
UIImage *image = info[UIImagePickerControllerOriginalImage];
// 添加图片到photosView中
[self.photosView addPhoto:image];
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// self.picking = NO;
// });
}
~~~