DSImagePickerController.m
2.1 KB
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
#import "DSImagePickerController.h"
@interface DSImagePickerController () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@end
@implementation DSImagePickerController
- (instancetype)initWithImagePickerStyle:(ImagePickerStyle)style delegate:(id<DSImagePickerControllerDelegate>)delegate {
if (self = [super init]) {
_dsDelegate = delegate;
self.allowsEditing = NO;
self.delegate = self;
if (style == ImagePickerStyleCamera) {
self.sourceType = UIImagePickerControllerSourceTypeCamera;
} else if (style == ImagePickerStylePhotoLibrary) {
self.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
}
return self;
}
#pragma mark - UINavigationControllerDelegate && 解决UIImagePickerController导航透明问题
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
if ([navigationController isKindOfClass:[UIImagePickerController class]]) {
self.navigationBarHidden = YES;
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
// 导航栏背景色
appearance.backgroundColor = DSBlack;
// 隐藏分割线
appearance.shadowColor = DSClearColor;
// 生效
self.navigationBar.scrollEdgeAppearance = appearance;
// 滚动视图滚动后导航栏背景色不会被影响
self.navigationBar.standardAppearance = appearance;
}
}
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
UIImage *editedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:nil];
if ([self.dsDelegate respondsToSelector:@selector(dsPickerImageFinished:)]) {
[self.dsDelegate dsPickerImageFinished:editedImage];
}
}
@end