猫猫学iOS 之微博项目实战(13)发送微博调用相机里面的图片以及调用相机

猫猫分享,必须精品

原创文章,欢迎转载。转载请注明:翟乃玉的博客
地址:http://blog.csdn.net/u013357243

一:效果

二:代码

相机部分就简单多了,几行代码调用而已,但是如果你要是想实现更多丰富的功能,需要自己写。利用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;
// });
}

你可能感兴趣的:(ios,代码,框架,微博,图片)