YMCustomCameraTopFunctionView.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // YMCustomCameraTopFunctionView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/17.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMCustomCameraTopFunctionView.h"
  9. #import "YMCustomCameraViewModel.h"
  10. @interface YMCustomCameraTopFunctionView ()
  11. /// 自定义相机VM
  12. @property (nonatomic, strong) YMCustomCameraViewModel *viewModel;
  13. /// 切换闪光灯模式按钮
  14. @property (nonatomic, strong) UIButton *switchFlashModeBtn;
  15. @end
  16. @implementation YMCustomCameraTopFunctionView
  17. - (void)ym_setupViews{
  18. [self addSubview:self.switchFlashModeBtn];
  19. [self setNeedsUpdateConstraints];
  20. [self updateConstraintsIfNeeded];
  21. }
  22. - (void)updateConstraints {
  23. [self.switchFlashModeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  24. make.centerX.equalTo(self.mas_centerX);
  25. make.centerY.equalTo(self.mas_centerY);
  26. make.width.height.mas_equalTo(adapt(40));
  27. }];
  28. [super updateConstraints];
  29. }
  30. - (void)ym_bindViewModel:(YMCustomCameraViewModel *)viewModel{
  31. if (!viewModel) {
  32. return;
  33. }
  34. _viewModel = viewModel;
  35. // @weakify(self)
  36. // [[[[RACObserve(self.viewModel, flashMode) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * flashMode) {
  37. // @strongify(self)
  38. // switch ([flashMode intValue]) {
  39. // case YMCaptureFlashModeOff:
  40. // {
  41. // [self.switchFlashModeBtn setTitle:@"关闭" forState:UIControlStateNormal];
  42. // }
  43. // break;
  44. // case YMCaptureFlashModeOn:
  45. // {
  46. // [self.switchFlashModeBtn setTitle:@"开启" forState:UIControlStateNormal];
  47. // }
  48. // break;
  49. // case YMCaptureFlashModeAuto:
  50. // {
  51. // [self.switchFlashModeBtn setTitle:@"自动" forState:UIControlStateNormal];
  52. // }
  53. // break;
  54. // default:
  55. // break;
  56. // }
  57. // }];
  58. }
  59. - (UIButton *)switchFlashModeBtn {
  60. if(!_switchFlashModeBtn){
  61. _switchFlashModeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  62. _switchFlashModeBtn.titleLabel.font = LCBoldFont(15);
  63. [_switchFlashModeBtn setTitle:@"自动" forState:UIControlStateNormal];
  64. [_switchFlashModeBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
  65. _switchFlashModeBtn.hidden = YES;
  66. WS(weakSelf)
  67. [[[_switchFlashModeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  68. [weakSelf.viewModel switchFlashMode];
  69. }];
  70. }
  71. return _switchFlashModeBtn;
  72. }
  73. @end