YMCustomCameraBottomFunctionView.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // YMCustomCameraBottomFunctionView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/17.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMCustomCameraBottomFunctionView.h"
  9. #import "YMCustomCameraViewModel.h"
  10. @interface YMCustomCameraBottomFunctionView ()
  11. /// 自定义相机VM
  12. @property (nonatomic, strong) YMCustomCameraViewModel *viewModel;
  13. /// 关闭按钮
  14. @property (nonatomic, strong) UIButton *closeBtn;
  15. /// 拍照按钮
  16. @property (nonatomic, strong) UIButton *takePhotoBtn;
  17. /// 切换前后摄像机按钮
  18. @property (nonatomic, strong) UIButton *switchFrontAndRearCameraBtn;
  19. @end
  20. @implementation YMCustomCameraBottomFunctionView
  21. - (void)ym_setupViews{
  22. [self addSubview:self.closeBtn];
  23. [self addSubview:self.takePhotoBtn];
  24. [self addSubview:self.switchFrontAndRearCameraBtn];
  25. [self setNeedsUpdateConstraints];
  26. [self updateConstraintsIfNeeded];
  27. }
  28. - (void)updateConstraints {
  29. [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.centerY.equalTo(self.takePhotoBtn.mas_centerY);
  31. make.left.equalTo(self).offset(adapt(20));
  32. make.width.mas_equalTo(adapt(60));
  33. make.height.mas_equalTo(adapt(30));
  34. }];
  35. [self.takePhotoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.centerX.equalTo(self.mas_centerX);
  37. make.centerY.equalTo(self.mas_centerY);
  38. make.width.height.mas_equalTo(adapt(60));
  39. }];
  40. [self.switchFrontAndRearCameraBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.centerY.equalTo(self.takePhotoBtn.mas_centerY);
  42. make.right.equalTo(self).offset(adapt(-20));
  43. make.width.height.mas_equalTo(adapt(30));
  44. }];
  45. [super updateConstraints];
  46. }
  47. - (void)ym_bindViewModel:(YMCustomCameraViewModel *)viewModel{
  48. if (!viewModel) {
  49. return;
  50. }
  51. _viewModel = viewModel;
  52. }
  53. - (UIButton *)closeBtn {
  54. if(!_closeBtn){
  55. _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  56. _closeBtn.titleLabel.font = LCBoldFont(15);
  57. [_closeBtn setTitle:@"取消" forState:UIControlStateNormal];
  58. [_closeBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
  59. WS(weakSelf)
  60. [[[_closeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  61. [weakSelf.viewModel closeCustomCamera];
  62. }];
  63. }
  64. return _closeBtn;
  65. }
  66. - (UIButton *)takePhotoBtn {
  67. if(!_takePhotoBtn){
  68. _takePhotoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  69. [_takePhotoBtn setBackgroundImage:ImageByName(@"ym_custom_camera_take_photo") forState:UIControlStateNormal];
  70. WS(weakSelf)
  71. [[[_takePhotoBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  72. [weakSelf.viewModel takePhoto];
  73. }];
  74. }
  75. return _takePhotoBtn;
  76. }
  77. - (UIButton *)switchFrontAndRearCameraBtn {
  78. if(!_switchFrontAndRearCameraBtn){
  79. _switchFrontAndRearCameraBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  80. [_switchFrontAndRearCameraBtn setBackgroundImage:ImageByName(@"ym_custom_camera_switch_front_and_rear_camera") forState:UIControlStateNormal];
  81. WS(weakSelf)
  82. [[[_switchFrontAndRearCameraBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  83. [weakSelf.viewModel switchFrontAndRearCamera];
  84. }];
  85. }
  86. return _switchFrontAndRearCameraBtn;
  87. }
  88. @end