CoachContractView.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // CoachContractView.m
  3. // LN_School
  4. //
  5. // Created by apple on 2017/10/23.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "CoachContractView.h"
  9. #import "PureCamera.h"
  10. #import "HKClipperHelper.h"
  11. @implementation CoachContractView
  12. /** h = 10 + (w - 20)*4/3 + 10 + 30 + 10 */
  13. - (instancetype)initWithFrame:(CGRect)frame {
  14. self = [super initWithFrame:frame];
  15. if (self) {
  16. self.backgroundColor = KBackGroundColor;
  17. CGFloat w = frame.size.width;
  18. _imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, w - 20, (w - 20)*4/3.0)];
  19. [_imgView borderColor:[UIColor grayColor] width:0.5 cornorRadios:3];
  20. _imgView.contentMode = UIViewContentModeScaleAspectFit;
  21. _imgView.image = [UIImage imageNamed:@"NOImg"];
  22. [self addSubview:_imgView];
  23. CGFloat y = (w - 20)*4.0/3.0 + 20;
  24. w = (w - 30)/2.0;
  25. NSArray *titleArray = @[@"拍照",@"删除"];
  26. for (int i = 0; i < 2; i ++) {
  27. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10 + i*(w + 10), y, w, 30)];
  28. btn.backgroundColor = defGreen;
  29. [btn setTitle:titleArray[i] textColor:KBackGroundColor font:Font17 fotState:UIControlStateNormal];
  30. [btn borderCornorRadios:4];
  31. [btn target:self Tag:i+1];
  32. [self addSubview:btn];
  33. }
  34. }
  35. return self;
  36. }
  37. - (void)btnClick:(UIButton *)sender {
  38. if (sender.tag == 1) {//拍照
  39. [self takePhoto];
  40. }else {//删除
  41. _imgView.image = [UIImage imageNamed:@"NOImg"];
  42. _isHavePhoto = NO;
  43. if (deleteBlock) {
  44. deleteBlock([NSString stringWithFormat:@"%d",(int)self.tag]);
  45. }
  46. }
  47. }
  48. - (void)deleteSelfWithBlock:(MyBlockType)block {
  49. deleteBlock = block;
  50. }
  51. //拍照
  52. - (void)takePhoto {
  53. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"请选择获取图片方式" preferredStyle:UIAlertControllerStyleAlert];
  54. //拍照
  55. UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  56. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  57. myDelegate.takePhotoAllRect = YES;
  58. PureCamera *homec = [[PureCamera alloc] init];
  59. homec.fininshcapture = ^(UIImage *photo) {
  60. //如果拍照过程取消 要另外处理
  61. myDelegate.takePhotoAllRect = NO;
  62. if (photo) {
  63. _imgView.image = photo;
  64. _isHavePhoto = YES;
  65. }
  66. };
  67. [_superVC presentViewController:homec
  68. animated:NO
  69. completion:nil];
  70. } else {
  71. NSLog(@"相机调用失败");
  72. }
  73. }];
  74. [alert addAction:cameraAction];
  75. //相册
  76. UIAlertAction *albumAction = [UIAlertAction actionWithTitle:@"本地照片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  77. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
  78. [HKClipperHelper shareManager].nav = _superVC.navigationController;
  79. [HKClipperHelper shareManager].clippedImgSize = _imgView.frame.size;
  80. [HKClipperHelper shareManager].clippedImageHandler = ^(UIImage *photo) {
  81. _imgView.image = photo;
  82. _isHavePhoto = YES;
  83. };
  84. [HKClipperHelper shareManager].clipperType = ClipperTypeImgMove;
  85. [HKClipperHelper shareManager].systemEditing = NO;
  86. [HKClipperHelper shareManager].isSystemType = NO;
  87. [[HKClipperHelper shareManager] photoWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
  88. }else{
  89. NSLog(@"相册调用失败");
  90. }
  91. }];
  92. [alert addAction:albumAction];
  93. [_superVC presentViewController:alert animated:NO completion:nil];
  94. }
  95. @end