// // CoachContractView.m // LN_School // // Created by apple on 2017/10/23. // Copyright © 2017年 Danson. All rights reserved. // #import "CoachContractView.h" #import "PureCamera.h" #import "HKClipperHelper.h" @implementation CoachContractView /** h = 10 + (w - 20)*4/3 + 10 + 30 + 10 */ - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = KBackGroundColor; CGFloat w = frame.size.width; _imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, w - 20, (w - 20)*4/3.0)]; [_imgView borderColor:[UIColor grayColor] width:0.5 cornorRadios:3]; _imgView.contentMode = UIViewContentModeScaleAspectFit; _imgView.image = [UIImage imageNamed:@"NOImg"]; [self addSubview:_imgView]; CGFloat y = (w - 20)*4.0/3.0 + 20; w = (w - 30)/2.0; NSArray *titleArray = @[@"拍照",@"删除"]; for (int i = 0; i < 2; i ++) { UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10 + i*(w + 10), y, w, 30)]; btn.backgroundColor = defGreen; [btn setTitle:titleArray[i] textColor:KBackGroundColor font:Font17 fotState:UIControlStateNormal]; [btn borderCornorRadios:4]; [btn target:self Tag:i+1]; [self addSubview:btn]; } } return self; } - (void)btnClick:(UIButton *)sender { if (sender.tag == 1) {//拍照 [self takePhoto]; }else {//删除 _imgView.image = [UIImage imageNamed:@"NOImg"]; _isHavePhoto = NO; if (deleteBlock) { deleteBlock([NSString stringWithFormat:@"%d",(int)self.tag]); } } } - (void)deleteSelfWithBlock:(MyBlockType)block { deleteBlock = block; } //拍照 - (void)takePhoto { UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"请选择获取图片方式" preferredStyle:UIAlertControllerStyleAlert]; //拍照 UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { myDelegate.takePhotoAllRect = YES; PureCamera *homec = [[PureCamera alloc] init]; homec.fininshcapture = ^(UIImage *photo) { //如果拍照过程取消 要另外处理 myDelegate.takePhotoAllRect = NO; if (photo) { _imgView.image = photo; _isHavePhoto = YES; } }; [_superVC presentViewController:homec animated:NO completion:nil]; } else { NSLog(@"相机调用失败"); } }]; [alert addAction:cameraAction]; //相册 UIAlertAction *albumAction = [UIAlertAction actionWithTitle:@"本地照片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) { [HKClipperHelper shareManager].nav = _superVC.navigationController; [HKClipperHelper shareManager].clippedImgSize = _imgView.frame.size; [HKClipperHelper shareManager].clippedImageHandler = ^(UIImage *photo) { _imgView.image = photo; _isHavePhoto = YES; }; [HKClipperHelper shareManager].clipperType = ClipperTypeImgMove; [HKClipperHelper shareManager].systemEditing = NO; [HKClipperHelper shareManager].isSystemType = NO; [[HKClipperHelper shareManager] photoWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; }else{ NSLog(@"相册调用失败"); } }]; [alert addAction:albumAction]; [_superVC presentViewController:alert animated:NO completion:nil]; } @end