// // WHBeautySheetView.m // WHChatV // // Created by 刘必果 on 2023/7/12. // #import "WHBeautySheetView.h" #import "UIDevice+StateHeight.h" #import "FUBeautyComponentManager.h" @interface WHBeautySheetView () /// 美颜视图选中功能索引,默认-1,-1表示未选中 @property (nonatomic, assign) NSInteger selectedIndex; @end @implementation WHBeautySheetView - (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if(self){ _beautySkinViewModel = [FUBeautyComponentManager sharedManager].beautySkinViewModel; _beautyShapeViewModel = [FUBeautyComponentManager sharedManager].beautyShapeViewModel; _beautyFilterViewModel = [FUBeautyComponentManager sharedManager].beautyFilterViewModel; [self loadUI]; [self loadLayout]; } return self; } - (void)loadUI{ [self addSubview:self.control]; [self addSubview:self.boxView]; [self.boxView addSubview:self.gapView]; [self.boxView addSubview:self.visualeView]; [self.boxView addSubview:self.beautySkinView]; [self.boxView addSubview:self.beautyShapeView]; [self.boxView addSubview:self.beautyFilterView]; [self.boxView addSubview:self.segmentBar]; } - (void)loadLayout{ [self.control mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self); }]; [self.boxView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self); make.bottom.equalTo(self.mas_bottom); make.height.mas_equalTo(WHScreenEqualWidth(200)+[UIDevice dev_safeDistanceBottom]); }]; [self.visualeView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.boxView); }]; [self.gapView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.boxView); make.height.mas_equalTo(WHScreenEqualWidth(1)); make.top.equalTo(self.boxView).offset(WHScreenEqualWidth(kFUBeautyFunctionViewOverallHeight)); }]; [self.segmentBar mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self); make.height.mas_equalTo( [UIDevice dev_safeDistanceBottom] + WHScreenEqualWidth(kFUBeautyCategoryViewHeight)); make.bottom.equalTo(self.boxView); }]; } - (void)dealloc{ [self saveBeautySource]; } - (void)saveBeautySource{ [self.beautySkinViewModel saveSkinsPersistently]; [self.beautyShapeViewModel saveShapesPersistently]; [self.beautyFilterViewModel saveFitersPersistently]; } - (void)closeAction{ [UIView animateWithDuration:0.25 animations:^{ CGFloat fH = WHScreenEqualWidth(200)+[UIDevice dev_safeDistanceBottom]; self.boxView.transform = CGAffineTransformMakeTranslation(0, fH); } completion:^(BOOL finished) { [self setHidden:YES]; }]; } - (void)showAnimin{ [self setHidden:NO]; [UIView animateWithDuration:0.25 animations:^{ self.boxView.transform = CGAffineTransformMakeTranslation(0, 0); } completion:^(BOOL finished) { }]; } #pragma mark - get set - (UIControl *)control{ if(!_control){ _control = [[UIControl alloc] init]; [_control addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside]; } return _control; } - (UIView *)boxView{ if(!_boxView){ _boxView = [[UIView alloc] init]; } return _boxView; } - (UIVisualEffectView *)visualeView{ if (!_visualeView) { UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; _visualeView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; } return _visualeView; } - (UIView *)gapView{ if(!_gapView){ _gapView = [[UIView alloc] init]; [_gapView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.5f]]; } return _gapView; } - (FUSegmentBar *)segmentBar{ if(!_segmentBar){ NSArray *categories = @[@"美肤", @"美型", @"滤镜"]; FUSegmentBarConfigurations *configurations = [[FUSegmentBarConfigurations alloc] init]; configurations.titleFont = [UIFont systemFontOfSize:15]; CGRect rect = CGRectMake(0, 0, kFrameWidth, [UIDevice dev_safeDistanceBottom] + WHScreenEqualWidth(kFUBeautyCategoryViewHeight)); _segmentBar = [[FUSegmentBar alloc] initWithFrame:rect titles:categories configuration:configurations]; _segmentBar.delegate = self; } return _segmentBar; } - (FUBeautySkinView *)beautySkinView { if (!_beautySkinView) { //83 _beautySkinView = [[FUBeautySkinView alloc] initWithFrame:CGRectMake(0, 0, kFrameWidth, WHScreenEqualWidth(kFUBeautyFunctionViewOverallHeight)) viewModel:self.beautySkinViewModel]; _beautySkinView.hidden = YES; } return _beautySkinView; } - (FUBeautyShapeView *)beautyShapeView { if (!_beautyShapeView) { _beautyShapeView = [[FUBeautyShapeView alloc] initWithFrame:CGRectMake(0, 0, kFrameWidth, WHScreenEqualWidth(kFUBeautyFunctionViewOverallHeight)) viewModel:self.beautyShapeViewModel]; _beautyShapeView.hidden = YES; } return _beautyShapeView; } - (FUBeautyFilterView *)beautyFilterView { if (!_beautyFilterView) { _beautyFilterView = [[FUBeautyFilterView alloc] initWithFrame:CGRectMake(0, 0, kFrameWidth, WHScreenEqualWidth(kFUBeautyFunctionViewOverallHeight)) viewModel:self.beautyFilterViewModel]; _beautyFilterView.hidden = YES; _beautyFilterView.delegate = self; } return _beautyFilterView; } //// WHBeautySheetView //- (FUBeautySkinViewModel *)beautySkinViewModel { // if (!_beautySkinViewModel) { // // _beautySkinViewModel = [[FUBeautySkinViewModel alloc] init]; // } // return _beautySkinViewModel; //} // //- (FUBeautyShapeViewModel *)beautyShapeViewModel { // if (!_beautyShapeViewModel) { // _beautyShapeViewModel = [[FUBeautyShapeViewModel alloc] init]; // } // return _beautyShapeViewModel; //} // //- (FUBeautyFilterViewModel *)beautyFilterViewModel { // if (!_beautyFilterViewModel) { // _beautyFilterViewModel = [[FUBeautyFilterViewModel alloc] init]; // } // return _beautyFilterViewModel; //} #pragma mark - FUSegmentBarDelegate - (void)segmentBar:(FUSegmentBar *)segmentBar didSelectItemAtIndex:(NSUInteger)index { // [segmentBar selectItemAtIndex:index]; [_beautySkinView setHidden:YES]; [_beautyShapeView setHidden:YES]; [_beautyFilterView setHidden:YES]; if(index == 0){ [_beautySkinView setHidden:NO]; }else if(index == 1){ [_beautyShapeView setHidden:NO]; }else{ [_beautyFilterView setHidden:NO]; } } - (BOOL)segmentBar:(FUSegmentBar *)segmentBar shouldSelectItemAtIndex:(NSInteger)index{ return YES; } - (BOOL)segmentBar:(FUSegmentBar *)segmentBar shouldDisableItemAtIndex:(NSInteger)index{ return YES; } #pragma mark - FUBeautyFilterViewDelegate - (void)beautyFilterViewDidChangeFilter:(NSString *)name { } @end