HeaderBackImgView.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // HeaderBackImgView.m
  3. // YBVideo
  4. //
  5. // Created by ybRRR on 2021/12/22.
  6. // Copyright © 2021 cat. All rights reserved.
  7. //
  8. #import "HeaderBackImgView.h"
  9. @implementation HeaderBackImgView
  10. -(void)hideTapClick{
  11. if (self.tapEvent) {
  12. self.tapEvent(@"hide");
  13. }
  14. }
  15. -(instancetype)initWithFrame:(CGRect)frame andHeadUrl:(NSString *)urls andUerid:(NSString *)userID
  16. {
  17. self = [super initWithFrame:frame];
  18. if (self) {
  19. self.backgroundColor = RGB(17,13,36);
  20. UITapGestureRecognizer *hideTaps = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideTapClick)];
  21. [self addGestureRecognizer:hideTaps];
  22. _headImgView = [[UIImageView alloc]init];
  23. _headImgView.frame = CGRectMake(0, 0, _window_width, _window_height);
  24. _headImgView.contentMode = UIViewContentModeScaleAspectFit;
  25. _headImgView.userInteractionEnabled = YES;
  26. [_headImgView sd_setImageWithURL:[NSURL URLWithString:urls]];
  27. [self addSubview:_headImgView];
  28. UIButton *changeBtn = [UIButton buttonWithType:0];
  29. changeBtn.frame = CGRectMake(0, _window_height-120, 213, 34);
  30. changeBtn.centerX = _headImgView.centerX;
  31. changeBtn.layer.cornerRadius = 5;
  32. changeBtn.layer.masksToBounds = YES;
  33. [changeBtn setBackgroundColor:RGB(29,26,46)];
  34. [changeBtn setTitle:YZMsg(@"更换") forState:0];
  35. [changeBtn setTitleColor:UIColor.whiteColor forState:0];
  36. changeBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  37. [changeBtn addTarget:self action:@selector(changeBtnClick) forControlEvents:UIControlEventTouchUpInside];
  38. [_headImgView addSubview:changeBtn];
  39. UIButton *downLoadBtn = [UIButton buttonWithType:0];
  40. downLoadBtn.frame = CGRectMake(_window_width-64, _window_height-64, 34, 34);
  41. [downLoadBtn setImage:[UIImage imageNamed:@"header_下载"] forState:0];
  42. [downLoadBtn addTarget:self action:@selector(downLoadBtnClick) forControlEvents:UIControlEventTouchUpInside];
  43. [_headImgView addSubview:downLoadBtn];
  44. if (![userID isEqual:[Config getOwnID]]) {
  45. changeBtn.hidden = YES;
  46. downLoadBtn.hidden = YES;
  47. }
  48. }
  49. return self;
  50. }
  51. -(void)changeBtnClick{
  52. YBWeakSelf;
  53. RKActionSheet *sheet = [[RKActionSheet alloc]initWithTitle:@""];
  54. [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"相机") complete:^{
  55. [weakSelf clickTake];
  56. }];
  57. [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"相册") complete:^{
  58. [weakSelf clickSel];
  59. }];
  60. [sheet addActionWithType:RKSheet_Cancle andTitle:YZMsg(@"取消") complete:^{
  61. }];
  62. [sheet showSheet];
  63. }
  64. -(void)downLoadBtnClick{
  65. UIImage *dowloadimg = _headImgView.image;
  66. [[PHPhotoLibrary sharedPhotoLibrary]performChanges:^{
  67. [PHAssetChangeRequest creationRequestForAssetFromImage:dowloadimg];
  68. } completionHandler:^(BOOL success, NSError * _Nullable error) {
  69. if (error) {
  70. NSLog(@"%@",@"保存失败");
  71. dispatch_async(dispatch_get_main_queue(), ^{
  72. [MBProgressHUD showError:YZMsg(@"保存失败")];
  73. });
  74. } else {
  75. NSLog(@"%@",@"保存成功");
  76. dispatch_async(dispatch_get_main_queue(), ^{
  77. [MBProgressHUD showError:YZMsg(@"保存成功")];
  78. });
  79. }
  80. }];
  81. }
  82. #pragma mark - UIImagePickerControllerDelegate
  83. //拍照
  84. -(void)clickTake {
  85. if (self.tapEvent) {
  86. self.tapEvent(@"拍照");
  87. }
  88. }
  89. -(void)clickSel {
  90. if (self.tapEvent) {
  91. self.tapEvent(@"相册");
  92. }
  93. }
  94. @end