封装相机功能->>>>>block返回image
来源:互联网 发布:删除淘宝中差评的公司 编辑:程序博客网 时间:2024/06/06 02:40
.h
#import <Foundation/Foundation.h>
@import UIKit;
typedef void(^Completion)(UIImage *image);
@interface ZSLImagePicker : NSObject
@property (copy,nonatomic) Completion completion;
- (void)completion:(Completion)completion;
+ (ZSLImagePicker *)defaultImagePicker;
- (void)startPickImageWithVC:(UIViewController *)vc;
@end
#import "ZSLImagePicker.h"
@interface ZSLImagePicker () <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@end
@implementation ZSLImagePicker
#pragma mark - public
+ (ZSLImagePicker *)defaultImagePicker
{
staticZSLImagePicker *imagePicker =nil;
staticdispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
imagePicker = [selfnew];
});
return imagePicker;
}
- (void)startPickImageWithVC:(UIViewController *)vc
{
UIAlertController *ac = [UIAlertControlleralertControllerWithTitle:nilmessage:@"添加照片"preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction *_Nonnull action) {
NSLog(@"cancelAction");
}];
UIAlertAction *takePhoto = [UIAlertActionactionWithTitle:@"拍照"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *_Nonnull action) {
NSLog(@"takePhoto");
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePC = [UIImagePickerControllernew];
imagePC.delegate =self;
imagePC.editing =YES;
imagePC.sourceType =UIImagePickerControllerSourceTypeCamera;
[vc presentViewController:imagePCanimated:YEScompletion:nil];
}else {
NSLog(@"无相机");
}
}];
UIAlertAction *selectPhoto = [UIAlertActionactionWithTitle:@"从相册选择 "style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *_Nonnull action) {
NSLog(@"selectPhoto");
UIImagePickerController *ipc = [UIImagePickerControllernew];
ipc.delegate = (id)self;
ipc.allowsEditing =YES;
ipc.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
[vc presentViewController:ipcanimated:YEScompletion:nil];
}];
[ac addAction:cancelAction];
[ac addAction:takePhoto];
[ac addAction:selectPhoto];
[vc presentViewController:acanimated:YEScompletion:nil];
}
- (void)completion:(Completion)completion
{
self.completion = completion;
}
#pragma mark - <UIImagePickerControllerDelegate>
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
if ([mediaTypeisEqualToString:@"public.image"]) {
//得到照片
UIImage *image = info[UIImagePickerControllerOriginalImage];
self.completion(image);
}
[picker dismissViewControllerAnimated:YEScompletion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YEScompletion:nil];
}
@end
#import "ViewController.h"
#import "ZSLImagePicker.h"
@interface ViewController ()
#pragma mark IB outlet
@property (weak,nonatomic) IBOutletUIImageView *imageView;
@end
@implementation ViewController
#pragma mark - IB action
- (IBAction)pickImage:(UIBarButtonItem *)sender
{
ZSLImagePicker *imagePicker = [ZSLImagePickerdefaultImagePicker];
[imagePicker startPickImageWithVC:self];
[imagePicker completion:^(UIImage *image) {
NSLog(@"aaa%@",image);
self.imageView.image = image;
}];
}
@end
- 封装相机功能->>>>>block返回image
- block,封装,函数参数,函数的返回值
- Android 启动系统相机功能 并返回所拍照片
- 只调用系统相机功能,而不需要返回拍照信息
- UBI-UnSorted Block Image
- Android 相机 III-相机功能
- image 相机vc+环境配置
- Block封装http请求
- ASI的封装 block
- iOS block与封装
- 调用手机相机功能
- android自定义相机功能
- 调用相机拍照功能
- 轮子---java返回image
- 相机获取不到返回数据
- image source相机snap模式采集
- block高级功能
- 手机,相机防抖功能
- Java路径问题最终解决方案—可定位所有资源的相对路径寻址(沈东良)
- linux 工具集合
- 2017.3.11 NOIP2017赛前模拟考试总结
- HTTP状态码
- 使用rowid去除oracle表中的重复项
- 封装相机功能->>>>>block返回image
- 观察者模式
- BZOJ 3940 [Usaco2015 Feb] Censoring
- 解析大型.NET ERP系统 20条数据库设计规范
- 创建一个helloworld springmvc的web工程
- Code Cache满导致接口性能变慢
- 根据中序遍历和先序遍历,后序遍历创建二叉树。
- 【Linux】Linux中常用操作命令
- cocos2d3.x android和ios屏蔽多点触摸