// // YMAudioVideoMatchingViewController.m // MSYOUPAI // // Created by YoMi on 2024/2/20. // Copyright © 2024 MS. All rights reserved. // #import "YMAudioVideoMatchingViewController.h" #import "YMAudioVideoMatchingViewModel.h" #import "YMAudioVideoMatchingTransitionView.h" #import "YMAudioVideoMatchingInfoPopupView.h" @interface YMAudioVideoMatchingViewController () /// 音视频匹配VM @property (nonatomic, strong) YMAudioVideoMatchingViewModel *viewModel; /// 容器滚动视图 @property (nonatomic, strong) UIScrollView *contentScrollView; /// 容器视图 @property (nonatomic, strong) UIView *contentView; /// 音视频匹配背景视图 @property (nonatomic, strong) UIImageView *audioVideoMatchingBgView; /// 音视频匹配过渡视图 @property (nonatomic, strong) YMAudioVideoMatchingTransitionView *audioVideoMatchingTransitionView; @end @implementation YMAudioVideoMatchingViewController @dynamic viewModel; - (void)viewDidLoad { [super viewDidLoad]; self.ym_navigationStyle = YMBaseNavigationStyleClearBgWhiteBackArrow; [OCNotificationCenter addObserver:self selector:@selector(audioVideoMatchingData:) name:AUDIO_VIDEO_MATCHING object:nil]; [OCNotificationCenter addObserver:self selector:@selector(audioVideoMatchingDataEND:) name:AUDIO_VIDEO_MATCHING_END object:nil]; id traget = self.navigationController.interactivePopGestureRecognizer.delegate; UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil]; [self.view addGestureRecognizer:pan]; @weakify(self) [self setLeftBarButtonWithImage:@"ym_navigation_white_icon" block:^(id _Nonnull sender) { @strongify(self) YMTipsPopupView *customView = [[YMTipsPopupView alloc]init]; customView.titleText = @"女神正在赶来的路上"; customView.titleFont = LCFont(16); customView.cancelTitle = @"继续匹配"; customView.cancelTitleColor = HexColorFromRGB(0x333333); customView.cancelBgColor = HexColorFromRGB(0xf5f5f5); customView.confirmTitle = @"放弃缘分"; customView.confirmTitleColor = HexColorFromRGB(0xFFFFFF); customView.confirmBgColor = HexColorFromRGB(0xff7ac2); [customView configutationWithTips:@"别错过缘分,再等等呐~" TipsAlignment:NSTextAlignmentCenter IsHideTitle:NO IsHideSingleButton:YES]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm) { @strongify(popupView) if (isConfirm) { [self.viewModel closeAudioVideoMatchingCompletion:^(BOOL finished) { [self.navigationController popViewControllerAnimated:YES]; }]; } [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; [popupView pop]; }]; } - (void)ym_setupViews{ [self.view addSubview:self.audioVideoMatchingBgView]; [self.view sendSubviewToBack:self.audioVideoMatchingBgView]; [self.audioVideoMatchingBgView addSubview:self.contentScrollView]; [self.contentScrollView addSubview:self.contentView]; [self.contentView addSubview:self.audioVideoMatchingTransitionView]; [self.view setNeedsUpdateConstraints]; [self.view updateConstraintsIfNeeded]; } - (void)updateViewConstraints{ [self.audioVideoMatchingBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view); make.left.equalTo(self.view); make.right.equalTo(self.view); make.bottom.equalTo(self.view); }]; [self.contentScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.audioVideoMatchingBgView); make.left.equalTo(self.audioVideoMatchingBgView); make.right.equalTo(self.audioVideoMatchingBgView); make.bottom.equalTo(self.audioVideoMatchingBgView); }]; [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.contentScrollView); make.width.equalTo(self.contentScrollView.mas_width); }]; [self.audioVideoMatchingTransitionView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(kYMNavHeight + adapt(10)); make.left.equalTo(self.contentView); make.right.equalTo(self.contentView); make.bottom.equalTo(self.contentView); }]; [super updateViewConstraints]; } - (void)ym_bindViewModel{ [self.audioVideoMatchingTransitionView ym_bindViewModel:self.viewModel]; [self.viewModel openAudioVideoMatchingCompletion:^(BOOL finished) { }]; } - (void)audioVideoMatchingDataEND:(NSNotification *)notice{ if (![self.viewModel isFemaleGender]) {// 如果不是女用户 男用户需要10秒以后才进入队列 [self.audioVideoMatchingTransitionView.countdownLab setHidden:NO]; __block NSInteger timeout= 10; //倒计时时间 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, timeout); dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,0 ,0 ,queue); dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行 dispatch_source_set_event_handler(_timer, ^{ if(timeout <= 0){ //倒计时结束,关闭 dispatch_source_cancel(_timer); dispatch_async(dispatch_get_main_queue(), ^{ //设置界面的按钮显示 根据自己需求设置 [self.audioVideoMatchingTransitionView.countdownLab setHidden:YES]; [self.viewModel openAudioVideoMatchingCompletion:^(BOOL finished) { }]; }); }else{ // int minutes = timeout / 60; NSInteger seconds = timeout % (10 + 1); dispatch_async(dispatch_get_main_queue(), ^{ //设置界面的按钮显示 根据自己需求设置 NSString *strTime = [NSString stringWithFormat:@"正在进入速配(%li)", seconds]; [self.audioVideoMatchingTransitionView.countdownLab setText:strTime]; }); timeout--; } }); dispatch_resume(_timer); } } - (void)audioVideoMatchingData:(NSNotification *)notice{ NSDictionary *data = [notice.userInfo dictionaryValueForKey:@"data" defaultValue:@{}]; if ([self.viewModel isFemaleGender]) { YMAudioVideoMatchingInfoPopupView *customView = [[YMAudioVideoMatchingInfoPopupView alloc]init]; [customView configutationWithDictionary:data]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSpringFromTop dismissStyle:YMDismissStyleSmoothToTop]; popupView.adjustY = kYMStatusBarHeight + adapt(10); popupView.isSingle = YES; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleTop; popupView.isClickBgDismiss = YES; popupView.isHideBg = YES; popupView.bgAlpha = 0.5; [popupView pop]; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSString * _Nonnull matchId, NSString * _Nonnull matchUserId) { @strongify(popupView) if (isConfirm) { WS(weakSelf) [self.viewModel receiveAudioVideoMatchingWithMatchId:matchId OfUserId:[matchUserId intValue]]; } [popupView dismissWithStyle:YMDismissStyleSmoothToTop duration:2.0]; }; } } - (UIScrollView *)contentScrollView{ if (!_contentScrollView) { _contentScrollView = [[UIScrollView alloc]init]; _contentScrollView.alwaysBounceVertical = YES; _contentScrollView.showsVerticalScrollIndicator = NO; _contentScrollView.showsHorizontalScrollIndicator = NO; _contentScrollView.backgroundColor = UIColor.clearColor; _contentScrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; } return _contentScrollView; } - (UIView *)contentView{ if (!_contentView) { _contentView = [[UIView alloc]init]; } return _contentView; } - (UIImageView *)audioVideoMatchingBgView{ if (!_audioVideoMatchingBgView) { _audioVideoMatchingBgView = [[UIImageView alloc]init]; _audioVideoMatchingBgView.contentMode = UIViewContentModeScaleAspectFill; _audioVideoMatchingBgView.image = ImageByName(@"ym_audio_video_matching_bg"); } return _audioVideoMatchingBgView; } - (YMAudioVideoMatchingTransitionView *)audioVideoMatchingTransitionView{ if (!_audioVideoMatchingTransitionView) { _audioVideoMatchingTransitionView = [[YMAudioVideoMatchingTransitionView alloc]init]; } return _audioVideoMatchingTransitionView; } - (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self name:AUDIO_VIDEO_MATCHING object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:AUDIO_VIDEO_MATCHING_END object:nil]; } @end