// // YMCustomCameraBottomFunctionView.m // MSYOUPAI // // Created by YoMi on 2024/3/17. // Copyright © 2024 MS. All rights reserved. // #import "YMCustomCameraBottomFunctionView.h" #import "YMCustomCameraViewModel.h" @interface YMCustomCameraBottomFunctionView () /// 自定义相机VM @property (nonatomic, strong) YMCustomCameraViewModel *viewModel; /// 关闭按钮 @property (nonatomic, strong) UIButton *closeBtn; /// 拍照按钮 @property (nonatomic, strong) UIButton *takePhotoBtn; /// 切换前后摄像机按钮 @property (nonatomic, strong) UIButton *switchFrontAndRearCameraBtn; @end @implementation YMCustomCameraBottomFunctionView - (void)ym_setupViews{ [self addSubview:self.closeBtn]; [self addSubview:self.takePhotoBtn]; [self addSubview:self.switchFrontAndRearCameraBtn]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints { [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.takePhotoBtn.mas_centerY); make.left.equalTo(self).offset(adapt(20)); make.width.mas_equalTo(adapt(60)); make.height.mas_equalTo(adapt(30)); }]; [self.takePhotoBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.mas_centerX); make.centerY.equalTo(self.mas_centerY); make.width.height.mas_equalTo(adapt(60)); }]; [self.switchFrontAndRearCameraBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.takePhotoBtn.mas_centerY); make.right.equalTo(self).offset(adapt(-20)); make.width.height.mas_equalTo(adapt(30)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMCustomCameraViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; } - (UIButton *)closeBtn { if(!_closeBtn){ _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _closeBtn.titleLabel.font = LCBoldFont(15); [_closeBtn setTitle:@"取消" forState:UIControlStateNormal]; [_closeBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal]; WS(weakSelf) [[[_closeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { [weakSelf.viewModel closeCustomCamera]; }]; } return _closeBtn; } - (UIButton *)takePhotoBtn { if(!_takePhotoBtn){ _takePhotoBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_takePhotoBtn setBackgroundImage:ImageByName(@"ym_custom_camera_take_photo") forState:UIControlStateNormal]; WS(weakSelf) [[[_takePhotoBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { [weakSelf.viewModel takePhoto]; }]; } return _takePhotoBtn; } - (UIButton *)switchFrontAndRearCameraBtn { if(!_switchFrontAndRearCameraBtn){ _switchFrontAndRearCameraBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_switchFrontAndRearCameraBtn setBackgroundImage:ImageByName(@"ym_custom_camera_switch_front_and_rear_camera") forState:UIControlStateNormal]; WS(weakSelf) [[[_switchFrontAndRearCameraBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { [weakSelf.viewModel switchFrontAndRearCamera]; }]; } return _switchFrontAndRearCameraBtn; } @end