12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- //
- // YMCustomCameraTopFunctionView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/3/17.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMCustomCameraTopFunctionView.h"
- #import "YMCustomCameraViewModel.h"
- @interface YMCustomCameraTopFunctionView ()
- /// 自定义相机VM
- @property (nonatomic, strong) YMCustomCameraViewModel *viewModel;
- /// 切换闪光灯模式按钮
- @property (nonatomic, strong) UIButton *switchFlashModeBtn;
- @end
- @implementation YMCustomCameraTopFunctionView
- - (void)ym_setupViews{
-
- [self addSubview:self.switchFlashModeBtn];
-
-
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints {
-
- [self.switchFlashModeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.mas_centerX);
- make.centerY.equalTo(self.mas_centerY);
- make.width.height.mas_equalTo(adapt(40));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMCustomCameraViewModel *)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
- // @weakify(self)
- // [[[[RACObserve(self.viewModel, flashMode) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * flashMode) {
- // @strongify(self)
- // switch ([flashMode intValue]) {
- // case YMCaptureFlashModeOff:
- // {
- // [self.switchFlashModeBtn setTitle:@"关闭" forState:UIControlStateNormal];
- // }
- // break;
- // case YMCaptureFlashModeOn:
- // {
- // [self.switchFlashModeBtn setTitle:@"开启" forState:UIControlStateNormal];
- // }
- // break;
- // case YMCaptureFlashModeAuto:
- // {
- // [self.switchFlashModeBtn setTitle:@"自动" forState:UIControlStateNormal];
- // }
- // break;
- // default:
- // break;
- // }
- // }];
-
- }
- - (UIButton *)switchFlashModeBtn {
- if(!_switchFlashModeBtn){
- _switchFlashModeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _switchFlashModeBtn.titleLabel.font = LCBoldFont(15);
- [_switchFlashModeBtn setTitle:@"自动" forState:UIControlStateNormal];
- [_switchFlashModeBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
- _switchFlashModeBtn.hidden = YES;
- WS(weakSelf)
- [[[_switchFlashModeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
- [weakSelf.viewModel switchFlashMode];
- }];
- }
- return _switchFlashModeBtn;
- }
- @end
|