FUBeautyViewController.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // FUBeautyViewController.m
  3. // FULiveDemo
  4. //
  5. // Created by 项林平 on 2022/7/26.
  6. //
  7. #import "FUBeautyViewController.h"
  8. #import "WHUtilsManager.h"
  9. @interface FUBeautyViewController ()<FUBeautyComponentDelegate, UIGestureRecognizerDelegate>
  10. @end
  11. @implementation FUBeautyViewController
  12. @dynamic viewModel;
  13. #pragma mark - Life cycle
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. [self hideBackButton];
  17. // [self customNavigationLeftImageItem:[UIImage imageNamed:@"WH_NavWhiteButton"] action:@selector(customBackAation)]; //白色的返回按钮
  18. UIButton * navBackBtn = [self customNavigationLeftTextItem:@"保存并退出" fontSize:WHScreenEqualWidth(14) color:[UIColor whiteColor] action:@selector(customBackAation)];
  19. [navBackBtn.layer setCornerRadius:WHScreenEqualWidth(16)];
  20. [navBackBtn.layer setBorderWidth:0.5f];
  21. [navBackBtn.layer setBorderColor:[UIColor whiteColor].CGColor];
  22. CGRect rect = navBackBtn.frame;
  23. rect.size.width = WHScreenEqualWidth(97);
  24. rect.size.height = WHScreenEqualWidth(32);
  25. [navBackBtn setFrame:rect];
  26. [self customNavigationRightImageItem:[UIImage imageNamed:@"WH_Beauty_Change"] action:@selector(chileHeadButtonViewSwitchAction:)];// 切换摄像头
  27. [self loadUI];
  28. [self loadLayout];
  29. [self.beautySheetView.segmentBar selectItemAtIndex:0];
  30. // 添加美颜视图
  31. [[FUBeautyComponentManager sharedManager] addComponentViewToView:self.view];
  32. [FUBeautyComponentManager sharedManager].delegate = self;
  33. }
  34. #pragma mark - 展示美颜设置View
  35. - (void)showSheetView{
  36. [self.beautySheetView showAnimin];
  37. }
  38. - (void)customBackAation{
  39. [WHUtilsManager alertSystemOfTitle:@"提示" message:@"是否保存设置?" certainBlock:^{
  40. [self.navigationController popViewControllerAnimated:YES];
  41. } cancleBlock:^{
  42. [self.navigationController popViewControllerAnimated:YES];
  43. }];
  44. }
  45. - (void)dealloc{
  46. if (self.viewModel.needsLoadingBeauty) {
  47. [FUBeautyComponentManager destory];
  48. }
  49. // 恢复相机曝光度
  50. [self.viewModel setCameraExposureValue:0];
  51. [self.viewModel stopCamera];
  52. [self.viewModel resetCameraSettings];
  53. [FURenderKitManager clearItems];
  54. }
  55. - (void)viewWillDisappear:(BOOL)animated{
  56. [super viewWillDisappear:animated];
  57. [self saveBeauty];
  58. }
  59. - (void)saveBeauty {
  60. [self.beautySheetView.beautySkinViewModel saveSkinsPersistently];
  61. [self.beautySheetView.beautyShapeViewModel saveShapesPersistently];
  62. [self.beautySheetView.beautyFilterViewModel saveFitersPersistently];
  63. }
  64. - (void)loadUI{
  65. [self.view addSubview:self.beautySheetView];
  66. }
  67. - (void)loadLayout{
  68. [self.beautySheetView mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.right.equalTo(self.view);
  70. make.height.mas_equalTo(kFrameHeight - [UIDevice dev_navigationFullHeight]);
  71. make.top.equalTo(self.view).offset([UIDevice dev_navigationFullHeight]);
  72. }];
  73. }
  74. - (WHBeautySheetView *)beautySheetView{
  75. if(!_beautySheetView){
  76. _beautySheetView = [[WHBeautySheetView alloc] init];
  77. }
  78. return _beautySheetView;
  79. }
  80. ///禁用栈底控制器的滑动返回
  81. /// 不允许手势饭回
  82. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
  83. return NO;
  84. }
  85. - (void)viewWillAppear:(BOOL)animated {
  86. [super viewWillAppear:animated];
  87. CGRect rect = CGRectMake(0, 0, [UIDevice dev_navigationFullHeight], kFrameWidth);
  88. CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  89. gradientLayer.colors = @[(__bridge id)[UIColor colorWithWhite:0 alpha:0.5f].CGColor,
  90. (__bridge id)[UIColor colorWithWhite:0 alpha:0].CGColor];
  91. gradientLayer.locations = @[@0.0,@1.0];
  92. gradientLayer.startPoint = CGPointMake(0.5, 0);
  93. gradientLayer.endPoint = CGPointMake(0.5, 1);
  94. gradientLayer.frame = rect;
  95. // gradientLayer.cornerRadius = radius;
  96. UIImage *image = [WHUtilsManager imageFromLayer:gradientLayer];
  97. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  98. if (@available(iOS 13.0, *)) {
  99. UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
  100. appearance.backgroundEffect = nil;
  101. appearance.shadowColor = [UIColor clearColor];
  102. appearance.backgroundImage = image;
  103. self.navigationController.navigationBar.standardAppearance = appearance;
  104. self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
  105. }else{
  106. self.navigationController.navigationBar.translucent = NO;
  107. // [self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.3f]];
  108. [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:(UIBarMetricsDefault)];
  109. [self.navigationController.navigationBar setTitleTextAttributes:nil];
  110. }
  111. // 更新拍照/录制按钮位置
  112. }
  113. #pragma mark - Event response
  114. - (void)dismissTipLabel {
  115. self.tipLabel.hidden = YES;
  116. }
  117. #pragma mark - FUBeautyComponentDelegate
  118. - (void)beautyComponentViewHeightDidChange:(CGFloat)height {
  119. // 美颜视图高度变化时需要更新拍照/录制按钮的位置
  120. // [self updateBottomConstraintsOfCaptureButton:height];
  121. }
  122. - (void)beautyComponentNeedsDisplayPromptContent:(NSString *)content {
  123. if (content.length == 0) {
  124. return;
  125. }
  126. dispatch_async(dispatch_get_main_queue(), ^{
  127. self.tipLabel.text = content;
  128. self.tipLabel.hidden = NO;
  129. [FUBeautyViewController cancelPreviousPerformRequestsWithTarget:self selector:@selector(dismissTipLabel) object:nil];
  130. [self performSelector:@selector(dismissTipLabel) withObject:nil afterDelay:1];
  131. });
  132. }
  133. #pragma mark - FUHeadButtonViewDelegate
  134. - (void)headButtonViewBackAction:(UIButton *)btn {
  135. [[FUBeautyComponentManager sharedManager] saveBeauty];
  136. // [super headButtonViewBackAction:btn];
  137. }
  138. @end