// // FUBeautyViewController.m // FULiveDemo // // Created by 项林平 on 2022/7/26. // #import "FUBeautyViewController.h" #import "WHUtilsManager.h" @interface FUBeautyViewController () @end @implementation FUBeautyViewController @dynamic viewModel; #pragma mark - Life cycle - (void)viewDidLoad { [super viewDidLoad]; [self hideBackButton]; // [self customNavigationLeftImageItem:[UIImage imageNamed:@"WH_NavWhiteButton"] action:@selector(customBackAation)]; //白色的返回按钮 UIButton * navBackBtn = [self customNavigationLeftTextItem:@"保存并退出" fontSize:WHScreenEqualWidth(14) color:[UIColor whiteColor] action:@selector(customBackAation)]; [navBackBtn.layer setCornerRadius:WHScreenEqualWidth(16)]; [navBackBtn.layer setBorderWidth:0.5f]; [navBackBtn.layer setBorderColor:[UIColor whiteColor].CGColor]; CGRect rect = navBackBtn.frame; rect.size.width = WHScreenEqualWidth(97); rect.size.height = WHScreenEqualWidth(32); [navBackBtn setFrame:rect]; [self customNavigationRightImageItem:[UIImage imageNamed:@"WH_Beauty_Change"] action:@selector(chileHeadButtonViewSwitchAction:)];// 切换摄像头 [self loadUI]; [self loadLayout]; [self.beautySheetView.segmentBar selectItemAtIndex:0]; // 添加美颜视图 [[FUBeautyComponentManager sharedManager] addComponentViewToView:self.view]; [FUBeautyComponentManager sharedManager].delegate = self; } #pragma mark - 展示美颜设置View - (void)showSheetView{ [self.beautySheetView showAnimin]; } - (void)customBackAation{ [WHUtilsManager alertSystemOfTitle:@"提示" message:@"是否保存设置?" certainBlock:^{ [self.navigationController popViewControllerAnimated:YES]; } cancleBlock:^{ [self.navigationController popViewControllerAnimated:YES]; }]; } - (void)dealloc{ if (self.viewModel.needsLoadingBeauty) { [FUBeautyComponentManager destory]; } // 恢复相机曝光度 [self.viewModel setCameraExposureValue:0]; [self.viewModel stopCamera]; [self.viewModel resetCameraSettings]; [FURenderKitManager clearItems]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self saveBeauty]; } - (void)saveBeauty { [self.beautySheetView.beautySkinViewModel saveSkinsPersistently]; [self.beautySheetView.beautyShapeViewModel saveShapesPersistently]; [self.beautySheetView.beautyFilterViewModel saveFitersPersistently]; } - (void)loadUI{ [self.view addSubview:self.beautySheetView]; } - (void)loadLayout{ [self.beautySheetView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); make.height.mas_equalTo(kFrameHeight - [UIDevice dev_navigationFullHeight]); make.top.equalTo(self.view).offset([UIDevice dev_navigationFullHeight]); }]; } - (WHBeautySheetView *)beautySheetView{ if(!_beautySheetView){ _beautySheetView = [[WHBeautySheetView alloc] init]; } return _beautySheetView; } ///禁用栈底控制器的滑动返回 /// 不允许手势饭回 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ return NO; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; CGRect rect = CGRectMake(0, 0, [UIDevice dev_navigationFullHeight], kFrameWidth); CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.colors = @[(__bridge id)[UIColor colorWithWhite:0 alpha:0.5f].CGColor, (__bridge id)[UIColor colorWithWhite:0 alpha:0].CGColor]; gradientLayer.locations = @[@0.0,@1.0]; gradientLayer.startPoint = CGPointMake(0.5, 0); gradientLayer.endPoint = CGPointMake(0.5, 1); gradientLayer.frame = rect; // gradientLayer.cornerRadius = radius; UIImage *image = [WHUtilsManager imageFromLayer:gradientLayer]; self.navigationController.interactivePopGestureRecognizer.delegate = self; if (@available(iOS 13.0, *)) { UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init]; appearance.backgroundEffect = nil; appearance.shadowColor = [UIColor clearColor]; appearance.backgroundImage = image; self.navigationController.navigationBar.standardAppearance = appearance; self.navigationController.navigationBar.scrollEdgeAppearance = appearance; }else{ self.navigationController.navigationBar.translucent = NO; // [self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.3f]]; [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:(UIBarMetricsDefault)]; [self.navigationController.navigationBar setTitleTextAttributes:nil]; } // 更新拍照/录制按钮位置 } #pragma mark - Event response - (void)dismissTipLabel { self.tipLabel.hidden = YES; } #pragma mark - FUBeautyComponentDelegate - (void)beautyComponentViewHeightDidChange:(CGFloat)height { // 美颜视图高度变化时需要更新拍照/录制按钮的位置 // [self updateBottomConstraintsOfCaptureButton:height]; } - (void)beautyComponentNeedsDisplayPromptContent:(NSString *)content { if (content.length == 0) { return; } dispatch_async(dispatch_get_main_queue(), ^{ self.tipLabel.text = content; self.tipLabel.hidden = NO; [FUBeautyViewController cancelPreviousPerformRequestsWithTarget:self selector:@selector(dismissTipLabel) object:nil]; [self performSelector:@selector(dismissTipLabel) withObject:nil afterDelay:1]; }); } #pragma mark - FUHeadButtonViewDelegate - (void)headButtonViewBackAction:(UIButton *)btn { [[FUBeautyComponentManager sharedManager] saveBeauty]; // [super headButtonViewBackAction:btn]; } @end