WHBeautySheetView.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // WHBeautySheetView.m
  3. // WHChatV
  4. //
  5. // Created by 刘必果 on 2023/7/12.
  6. //
  7. #import "WHBeautySheetView.h"
  8. #import "UIDevice+StateHeight.h"
  9. #import "FUBeautyComponentManager.h"
  10. @interface WHBeautySheetView ()
  11. /// 美颜视图选中功能索引,默认-1,-1表示未选中
  12. @property (nonatomic, assign) NSInteger selectedIndex;
  13. @end
  14. @implementation WHBeautySheetView
  15. - (instancetype)initWithFrame:(CGRect)frame{
  16. self = [super initWithFrame:frame];
  17. if(self){
  18. _beautySkinViewModel = [FUBeautyComponentManager sharedManager].beautySkinViewModel;
  19. _beautyShapeViewModel = [FUBeautyComponentManager sharedManager].beautyShapeViewModel;
  20. _beautyFilterViewModel = [FUBeautyComponentManager sharedManager].beautyFilterViewModel;
  21. [self loadUI];
  22. [self loadLayout];
  23. }
  24. return self;
  25. }
  26. - (void)loadUI{
  27. [self addSubview:self.control];
  28. [self addSubview:self.boxView];
  29. [self.boxView addSubview:self.gapView];
  30. [self.boxView addSubview:self.visualeView];
  31. [self.boxView addSubview:self.beautySkinView];
  32. [self.boxView addSubview:self.beautyShapeView];
  33. [self.boxView addSubview:self.beautyFilterView];
  34. [self.boxView addSubview:self.segmentBar];
  35. }
  36. - (void)loadLayout{
  37. [self.control mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.edges.equalTo(self);
  39. }];
  40. [self.boxView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.right.equalTo(self);
  42. make.bottom.equalTo(self.mas_bottom);
  43. make.height.mas_equalTo(WHScreenEqualWidth(200)+[UIDevice dev_safeDistanceBottom]);
  44. }];
  45. [self.visualeView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.edges.equalTo(self.boxView);
  47. }];
  48. [self.gapView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.right.equalTo(self.boxView);
  50. make.height.mas_equalTo(WHScreenEqualWidth(1));
  51. make.top.equalTo(self.boxView).offset(WHScreenEqualWidth(kFUBeautyFunctionViewOverallHeight));
  52. }];
  53. [self.segmentBar mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.right.equalTo(self);
  55. make.height.mas_equalTo( [UIDevice dev_safeDistanceBottom] + WHScreenEqualWidth(kFUBeautyCategoryViewHeight));
  56. make.bottom.equalTo(self.boxView);
  57. }];
  58. }
  59. - (void)dealloc{
  60. [self saveBeautySource];
  61. }
  62. - (void)saveBeautySource{
  63. [self.beautySkinViewModel saveSkinsPersistently];
  64. [self.beautyShapeViewModel saveShapesPersistently];
  65. [self.beautyFilterViewModel saveFitersPersistently];
  66. }
  67. - (void)closeAction{
  68. [UIView animateWithDuration:0.25 animations:^{
  69. CGFloat fH = WHScreenEqualWidth(200)+[UIDevice dev_safeDistanceBottom];
  70. self.boxView.transform = CGAffineTransformMakeTranslation(0, fH);
  71. } completion:^(BOOL finished) {
  72. [self setHidden:YES];
  73. }];
  74. }
  75. - (void)showAnimin{
  76. [self setHidden:NO];
  77. [UIView animateWithDuration:0.25 animations:^{
  78. self.boxView.transform = CGAffineTransformMakeTranslation(0, 0);
  79. } completion:^(BOOL finished) {
  80. }];
  81. }
  82. #pragma mark - get set
  83. - (UIControl *)control{
  84. if(!_control){
  85. _control = [[UIControl alloc] init];
  86. [_control addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  87. }
  88. return _control;
  89. }
  90. - (UIView *)boxView{
  91. if(!_boxView){
  92. _boxView = [[UIView alloc] init];
  93. }
  94. return _boxView;
  95. }
  96. - (UIVisualEffectView *)visualeView{
  97. if (!_visualeView) {
  98. UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  99. _visualeView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  100. }
  101. return _visualeView;
  102. }
  103. - (UIView *)gapView{
  104. if(!_gapView){
  105. _gapView = [[UIView alloc] init];
  106. [_gapView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.5f]];
  107. }
  108. return _gapView;
  109. }
  110. - (FUSegmentBar *)segmentBar{
  111. if(!_segmentBar){
  112. NSArray<NSString *> *categories = @[@"美肤", @"美型", @"滤镜"];
  113. FUSegmentBarConfigurations *configurations = [[FUSegmentBarConfigurations alloc] init];
  114. configurations.titleFont = [UIFont systemFontOfSize:15];
  115. CGRect rect = CGRectMake(0, 0, kFrameWidth, [UIDevice dev_safeDistanceBottom] + WHScreenEqualWidth(kFUBeautyCategoryViewHeight));
  116. _segmentBar = [[FUSegmentBar alloc] initWithFrame:rect titles:categories configuration:configurations];
  117. _segmentBar.delegate = self;
  118. }
  119. return _segmentBar;
  120. }
  121. - (FUBeautySkinView *)beautySkinView {
  122. if (!_beautySkinView) {
  123. //83
  124. _beautySkinView = [[FUBeautySkinView alloc] initWithFrame:CGRectMake(0, 0, kFrameWidth, WHScreenEqualWidth(kFUBeautyFunctionViewOverallHeight)) viewModel:self.beautySkinViewModel];
  125. _beautySkinView.hidden = YES;
  126. }
  127. return _beautySkinView;
  128. }
  129. - (FUBeautyShapeView *)beautyShapeView {
  130. if (!_beautyShapeView) {
  131. _beautyShapeView = [[FUBeautyShapeView alloc] initWithFrame:CGRectMake(0, 0, kFrameWidth, WHScreenEqualWidth(kFUBeautyFunctionViewOverallHeight)) viewModel:self.beautyShapeViewModel];
  132. _beautyShapeView.hidden = YES;
  133. }
  134. return _beautyShapeView;
  135. }
  136. - (FUBeautyFilterView *)beautyFilterView {
  137. if (!_beautyFilterView) {
  138. _beautyFilterView = [[FUBeautyFilterView alloc] initWithFrame:CGRectMake(0, 0, kFrameWidth, WHScreenEqualWidth(kFUBeautyFunctionViewOverallHeight)) viewModel:self.beautyFilterViewModel];
  139. _beautyFilterView.hidden = YES;
  140. _beautyFilterView.delegate = self;
  141. }
  142. return _beautyFilterView;
  143. }
  144. //// WHBeautySheetView
  145. //- (FUBeautySkinViewModel *)beautySkinViewModel {
  146. // if (!_beautySkinViewModel) {
  147. //
  148. // _beautySkinViewModel = [[FUBeautySkinViewModel alloc] init];
  149. // }
  150. // return _beautySkinViewModel;
  151. //}
  152. //
  153. //- (FUBeautyShapeViewModel *)beautyShapeViewModel {
  154. // if (!_beautyShapeViewModel) {
  155. // _beautyShapeViewModel = [[FUBeautyShapeViewModel alloc] init];
  156. // }
  157. // return _beautyShapeViewModel;
  158. //}
  159. //
  160. //- (FUBeautyFilterViewModel *)beautyFilterViewModel {
  161. // if (!_beautyFilterViewModel) {
  162. // _beautyFilterViewModel = [[FUBeautyFilterViewModel alloc] init];
  163. // }
  164. // return _beautyFilterViewModel;
  165. //}
  166. #pragma mark - FUSegmentBarDelegate
  167. - (void)segmentBar:(FUSegmentBar *)segmentBar didSelectItemAtIndex:(NSUInteger)index {
  168. // [segmentBar selectItemAtIndex:index];
  169. [_beautySkinView setHidden:YES];
  170. [_beautyShapeView setHidden:YES];
  171. [_beautyFilterView setHidden:YES];
  172. if(index == 0){
  173. [_beautySkinView setHidden:NO];
  174. }else if(index == 1){
  175. [_beautyShapeView setHidden:NO];
  176. }else{
  177. [_beautyFilterView setHidden:NO];
  178. }
  179. }
  180. - (BOOL)segmentBar:(FUSegmentBar *)segmentBar shouldSelectItemAtIndex:(NSInteger)index{
  181. return YES;
  182. }
  183. - (BOOL)segmentBar:(FUSegmentBar *)segmentBar shouldDisableItemAtIndex:(NSInteger)index{
  184. return YES;
  185. }
  186. #pragma mark - FUBeautyFilterViewDelegate
  187. - (void)beautyFilterViewDidChangeFilter:(NSString *)name {
  188. }
  189. @end