-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathZMImagePickerSource.m
executable file
·71 lines (55 loc) · 2.34 KB
/
ZMImagePickerSource.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// ZMImagePickerSource.m
// HarierAirCondition
//
// Created by Lion on 13-7-9.
// Copyright (c) 2013年 Lion. All rights reserved.
//
#import "ZMImagePickerSource.h"
#import "ZMActionSheetBlock.h"
#import "ZMImagePickerControllerBlock.h"
#import "UIImage+ResizeImage.h"
@interface ZMImagePickerSource ()
@property (nonatomic, copy) ImagePickerBackBlock callBackBlock;
@property (weak ,nonatomic) UIViewController *viewController;
@end
@implementation ZMImagePickerSource
- (void)dealloc
{
NSLog(@"ZMImagePickerSource dealloc");
}
+ (void)chooseImageFromViewController:(UIViewController *) viewController
allowEditing:(BOOL) editing
imageMaxSizeLength:(CGFloat)lenght
CompletionHandler:(ImagePickerBackBlock ) handler
{
ZMImagePickerSource *imagePickerSource = [[ZMImagePickerSource alloc] init];
imagePickerSource.viewController = viewController;
imagePickerSource.callBackBlock = handler;
ZMActionSheetBlock *actionSheet = [[ZMActionSheetBlock alloc]initWithTitle:nil delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"从相册选取",nil];
[actionSheet showInView:viewController.view DissmissHandler:^(NSInteger selecedIndex) {
NSLog(@"selectedIndex:%d",selecedIndex);
ZMImagePickerControllerBlock *imagePicker = [[ZMImagePickerControllerBlock alloc] init];
imagePicker.allowsEditing = editing;
if (0 == selecedIndex) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else if (1 == selecedIndex) {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[imagePicker showWithModalViewController:imagePickerSource.viewController animated:YES selectedHandler:^(UIImage *image, NSDictionary *info, BOOL *dismiss) {
//resize image
UIImage *lastImage = nil;
if (lenght > 0) {
lastImage = [image imageWithMaxSide:lenght];
} else {
lastImage = image;
}
imagePickerSource.callBackBlock(lastImage,info,dismiss);
} cancel:^{
NSLog(@"ZMImagePickerControllerBlock cancel");
}];
} cancelHandler:^{
NSLog(@"actionsheet cancel");
}];
}
@end