123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- //
- // XYMakingFriendsMainViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/12/4.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYMakingFriendsMainViewController.h"
- #import "XYVoiceMatchViewController.h"
- #import "XYMakingFriendsSkillViewController.h"
- #import "XYMakingFriendsMainSkillMaskView.h"
- #import "XYMarkingFriendsMainSkillTopView.h"
- #import "XYPeiPlayUserInfoEditAlertView.h"
- /*
- 滑动生效距离
- */
- #define SlideDistance 50.0f
- typedef enum : NSUInteger {
- XYMakingFriendsSlideStateNormal, // 默认状态(显示语音速配)
- XYMakingFriendsSlideStateUpSlideing, // 向上滑动中(松手进入切换状态中)
- XYMakingFriendsSlideStateShowSkill, // 显示技能列表(动画已结束)
- XYMakingFriendsSlideStateDownSlideing, // 向下滑动中(松手今日切换到速配界面动画中)
- } XYMakingFriendsSlideState;
- @interface XYMakingFriendsMainViewController ()
- @property (nonatomic, strong) UIView *voiceMatchingView;
- @property (nonatomic, strong) UIImageView *voiceMatchingBgImageView;
- @property (nonatomic, strong) XYVoiceMatchViewController *voiceMatchViewController;
- @property (nonatomic, strong) UIView *middleView;
- @property (nonatomic, strong) UIImageView *middleBgView;
- @property (nonatomic, strong) UIImageView *middleImageView;
- @property (nonatomic, strong) XYMarkingFriendsMainSkillTopView *skillTopView;
- @property (nonatomic, strong) UIView *listView;
- @property (nonatomic, strong) UIImageView *listMenuBgImageView;
- @property (nonatomic, strong) XYMakingFriendsSkillViewController *skillViewController;
- /// 列表蒙版
- @property (nonatomic, strong) XYMakingFriendsMainSkillMaskView *listMaskView;
- @property (nonatomic, assign) XYMakingFriendsSlideState slideState;
- /// 下拉开始的触摸点
- @property (nonatomic, assign) CGPoint downBeginPoint;
- @property (nonatomic, assign) CGFloat currentSkillListScrollOffsetY;
- @end
- @implementation XYMakingFriendsMainViewController
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self name:@"SKILL_LIST_SCROLL_OFFSET_Y" object:nil];
- }
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.prefersNavigationBarHidden = YES;
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- // 设置默认状态
- self.slideState = XYMakingFriendsSlideStateNormal;
-
- [self setupUI];
-
- // 添加拖动手势
- // self.view.userInteractionEnabled = YES;
- // UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
- // [self.view addGestureRecognizer:pan];
- // v1.10
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveSkillListScrollOffsetYNotification:) name:@"SKILL_LIST_SCROLL_OFFSET_Y" object:nil];
-
- //资料完善度提醒(内部做分数判断)
- [[XYPeiPlayUserInfoEditAlertView shareInstance] show:JoinTypeVoiceChat];
- }
- - (void)setupUI {
- [self.view addSubview:self.middleView];
- [self.middleView addSubview:self.middleBgView];
- [self.middleView addSubview:self.middleImageView];
- [self.middleView addSubview:self.skillTopView];
-
- [self.view addSubview:self.voiceMatchingView];
-
- [self.view addSubview:self.listView];
- }
- - (void)saveSkillListScrollOffsetYNotification:(NSNotification *)notification {
- CGFloat offsetY = [notification.object[@"offsetY"] floatValue];
- self.currentSkillListScrollOffsetY = offsetY;
- }
- #pragma mark — Action
- - (void)panAction:(UIPanGestureRecognizer *)panGestureRecognizer {
- CGPoint movePoint = [panGestureRecognizer translationInView:self.view];
- NSLog(@"movePoint:%@", NSStringFromCGPoint(movePoint));
- if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
- // 只处理下拉触发点 进行保存 用来判断触摸的是哪个位置
- if (self.slideState == XYMakingFriendsSlideStateShowSkill) {
- // 获取触摸点
- CGPoint locationPoint = [panGestureRecognizer locationInView:self.view];
- self.downBeginPoint = locationPoint;
- }
- }else if (panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
- switch (self.slideState) {
- case XYMakingFriendsSlideStateNormal:
- case XYMakingFriendsSlideStateUpSlideing:
- // 根据滑动距离切换状态
- if (movePoint.y > 0) {
- return;
- }
- self.voiceMatchingView.frame = CGRectMake(self.voiceMatchingView.f_x, movePoint.y, self.voiceMatchingView.f_width, self.voiceMatchingView.f_heigh);
- self.listView.frame = CGRectMake(self.listView.f_x, self.voiceMatchingView.f_top-68.0f, self.listView.f_width, self.listView.f_heigh);
- if (movePoint.y > -SlideDistance) {
- // 回复原位
- self.slideState = XYMakingFriendsSlideStateNormal;
- }else {
- // 松手则进入刷新状态
- self.slideState = XYMakingFriendsSlideStateUpSlideing;
- }
- break;
- case XYMakingFriendsSlideStateShowSkill:
- {
- // 根据滑动距离切换状态
- if (movePoint.y < 0) {
- return;
- }
- if (self.downBeginPoint.y < (STATUS_HEIGHT+48.0f+20.0f)) {
- // 触发点在顶部中间层
- self.middleView.frame = CGRectMake(self.middleView.f_x, -self.middleView.f_heigh+self.middleImageView.f_heigh+movePoint.y, self.middleView.f_width, self.middleView.f_heigh);
- self.listView.frame = CGRectMake(self.listView.f_x, STATUS_HEIGHT+48.0f+movePoint.y, self.listView.f_width, self.listView.f_heigh);
- }else {
- if (self.currentSkillListScrollOffsetY > 0 ) {
- return;
- }
- // 触发点在skillView上
- self.skillViewController.view.frame = CGRectMake(self.skillViewController.view.f_x, 20.0f+movePoint.y, self.skillViewController.view.f_width, self.skillViewController.view.f_heigh);
- }
- if (movePoint.y < SlideDistance) {
- // 回复原位
- self.slideState = XYMakingFriendsSlideStateShowSkill;
- }else {
- // 松手则进入刷新状态
- self.slideState = XYMakingFriendsSlideStateDownSlideing;
- }
- // 交友Tab,点底部区域[上滑]的次数
- // [StatisticsManager event:@"match_slideup_click"];
- }
- break;
- case XYMakingFriendsSlideStateDownSlideing:
- // 根据滑动距离切换状态
- if (movePoint.y < 0) {
- return;
- }
- if (self.downBeginPoint.y < (STATUS_HEIGHT+48.0f+20.0f)) {
- // 触发点在顶部中间层
- self.middleView.frame = CGRectMake(self.middleView.f_x, -self.middleView.f_heigh+self.middleImageView.f_heigh+movePoint.y, self.middleView.f_width, self.middleView.f_heigh);
- self.listView.frame = CGRectMake(self.listView.f_x, STATUS_HEIGHT+48.0f+movePoint.y, self.listView.f_width, self.listView.f_heigh);
- }else {
- // 触发点在skillView上
- self.skillViewController.view.frame = CGRectMake(self.skillViewController.view.f_x, 20.0f+movePoint.y, self.skillViewController.view.f_width, self.skillViewController.view.f_heigh);
- }
- if (movePoint.y < SlideDistance) {
- // 回复原位
- self.slideState = XYMakingFriendsSlideStateShowSkill;
- }else {
- // 松手则进入刷新状态
- self.slideState = XYMakingFriendsSlideStateDownSlideing;
- }
- break;
- default:
- // 其他状态不需要处理
- break;
- }
- }else if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) {
- // 销毁保存的触摸点
- self.downBeginPoint = CGPointZero;
- [self changeState:self.slideState];
- }
- }
- /// 快速匹配
- - (void)quickMatchAction {
-
- self.slideState = XYMakingFriendsSlideStateDownSlideing;
- [self changeState:self.slideState];
-
- // 开启匹配/取消匹配
- [self.voiceMatchViewController startVoiceMatch];
- }
- - (void)changeState:(XYMakingFriendsSlideState)state {
- switch (state) {
- case XYMakingFriendsSlideStateNormal:
- {
- // 回复到原状态
- [UIView animateWithDuration:.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
- self.voiceMatchingView.frame = CGRectMake(self.voiceMatchingView.f_x, 0, self.voiceMatchingView.f_width, self.voiceMatchingView.f_heigh);
- self.listView.frame = CGRectMake(self.listView.f_x, self.voiceMatchingView.f_top-68.0f, self.listView.f_width, self.listView.f_heigh);
- } completion:^(BOOL finished) {
-
- }];
- }
- break;
- case XYMakingFriendsSlideStateUpSlideing:
- {
- // 切换到技能界面
- [UIView animateWithDuration:.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
- self.voiceMatchingView.frame = CGRectMake(self.voiceMatchingView.f_x, -self.voiceMatchingView.f_heigh+68.0f, self.voiceMatchingView.f_width, self.voiceMatchingView.f_heigh);
- self.listView.frame = CGRectMake(self.listView.f_x, self.voiceMatchingView.f_top-68.0f, self.listView.f_width, self.listView.f_heigh);
- } completion:^(BOOL finished) {
- self.skillTopView.hidden = NO;
- [UIView animateWithDuration:.2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
- self.voiceMatchingView.frame = CGRectMake(self.voiceMatchingView.f_x, -self.voiceMatchingView.f_heigh, self.voiceMatchingView.f_width, self.voiceMatchingView.f_heigh);
- self.middleView.frame = CGRectMake(self.middleView.f_x, -self.middleView.f_heigh+self.middleImageView.f_heigh, self.middleView.f_width, self.middleView.f_heigh);
- self.listView.frame = CGRectMake(self.listView.f_x, STATUS_HEIGHT+48.0f, self.listView.f_width, self.listView.f_heigh);
- } completion:^(BOOL finished) {
- // 切换状态
- self.slideState = XYMakingFriendsSlideStateShowSkill;
- self.listMaskView.hidden = YES;
- if (self.voiceMatchViewController.matchStatus == XYVoiceMatchingStatusOpenMatching) {
- // 匹配中 则需要取消匹配
- [self.voiceMatchViewController startVoiceMatch];
- }
- }];
- }];
- }
- break;
- case XYMakingFriendsSlideStateShowSkill:
- {
- // 回复到技能界面
- [UIView animateWithDuration:.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
- self.middleView.frame = CGRectMake(self.middleView.f_x, -self.middleView.f_heigh+self.middleImageView.f_heigh, self.middleView.f_width, self.middleView.f_heigh);
- self.listView.frame = CGRectMake(self.listView.f_x, STATUS_HEIGHT+48.0f, self.listView.f_width, self.listView.f_heigh);
- self.skillViewController.view.frame = CGRectMake(self.skillViewController.view.f_x, 20.0f, self.skillViewController.view.f_width, self.skillViewController.view.f_heigh);
- } completion:^(BOOL finished) {
-
- }];
- }
- break;
- case XYMakingFriendsSlideStateDownSlideing:
- {
- // 切换到原始状态
- // 开始显示速配动画
- [UIView animateWithDuration:.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
- self.middleView.frame = CGRectMake(self.middleView.f_x, -self.middleView.f_heigh, self.middleView.f_width, self.middleView.f_heigh);
- self.voiceMatchingView.frame = CGRectMake(self.voiceMatchingView.f_x, 0, self.voiceMatchingView.f_width, self.voiceMatchingView.f_heigh);
- self.listView.frame = CGRectMake(self.listView.f_x, self.voiceMatchingView.f_top-68.0f, self.listView.f_width, self.listView.f_heigh);
- self.skillViewController.view.frame = CGRectMake(self.skillViewController.view.f_x, 20.0f, self.skillViewController.view.f_width, self.skillViewController.view.f_heigh);
- } completion:^(BOOL finished) {
- // 切换状态
- self.slideState = XYMakingFriendsSlideStateNormal;
- self.listMaskView.hidden = NO;
- self.skillTopView.hidden = YES;
- }];
- }
- break;
- }
- }
- #pragma mark — Getter
- - (UIView *)voiceMatchingView {
- if (!_voiceMatchingView) {
- _voiceMatchingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
-
- _voiceMatchingBgImageView = [[UIImageView alloc] initWithFrame:self.voiceMatchingView.bounds];
- _voiceMatchingBgImageView.image = ImageNamed(@"xy_friend_qm_bg");
- [_voiceMatchingView addSubview:_voiceMatchingBgImageView];
-
- _voiceMatchViewController = XYVoiceMatchViewController.new;
- [self addChildViewController:_voiceMatchViewController];
- [_voiceMatchingView addSubview:_voiceMatchViewController.view];
- _voiceMatchViewController.view.frame = _voiceMatchingView.bounds;
-
- kWEAKSELF
- _voiceMatchViewController.XYVoiceMatchViewControllerUserArrsBlock = ^(NSMutableArray * _Nonnull userArrs) {
- [weakSelf.skillTopView setupMatchUserArray:userArrs];
- };
- }
- return _voiceMatchingView;
- }
- - (UIImageView *)voiceMatchingBgImageView {
- if (!_voiceMatchingBgImageView) {
- _voiceMatchingBgImageView = [[UIImageView alloc] initWithFrame:self.voiceMatchingView.bounds];
- _voiceMatchingBgImageView.image = ImageNamed(@"xy_friend_qm_bg");
- }
- return _voiceMatchingBgImageView;
- }
- - (UIView *)middleView {
- if (!_middleView) {
- _middleView = [[UIView alloc] initWithFrame:CGRectMake(0, -SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-TABBAR_HEIGHT)];
- _middleView.backgroundColor = Color_Clear;
- }
- return _middleView;
- }
- - (UIImageView *)middleBgView {
- if (!_middleBgView) {
- _middleBgView = [[UIImageView alloc] initWithFrame:self.middleView.bounds];
- _middleBgView.image = ImageNamed(@"xy_friend_qm_bg");
- }
- return _middleBgView;
- }
- - (UIImageView *)middleImageView {
- if (!_middleImageView) {
- _middleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.middleView.f_heigh-136.0f, self.middleView.f_width, 136.0f)];
- _middleImageView.image = ImageNamed(@"xy_friend_middle_bg");
- }
- return _middleImageView;
- }
- - (XYMarkingFriendsMainSkillTopView *)skillTopView {
- if (!_skillTopView) {
- _skillTopView = [[XYMarkingFriendsMainSkillTopView alloc] initWithFrame:CGRectMake(0, self.middleImageView.f_y+STATUS_HEIGHT, self.middleView.f_width, 48.0f)];
- _skillTopView.hidden = YES;
- WeakSelf
- [_skillTopView setQuickMatchBlock:^{
- // 快速匹配
- [weakSelf quickMatchAction];
- }];
- }
- return _skillTopView;
- }
- - (UIView *)listView {
- if (!_listView) {
- // _listView = [[UIView alloc] initWithFrame:CGRectMake(0, self.voiceMatchingView.f_top-68.0f, SCREEN_WIDTH, SCREEN_HEIGHT - STATUS_HEIGHT - 48.0f)];
- // _listView.backgroundColor = Color_Clear;
- //
- // _listMenuBgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 68.0f)];
- // _listMenuBgImageView.image = ImageNamed(@"xy_friend_menu_bg");
- // [_listView addSubview:_listMenuBgImageView];
- //
- // _skillViewController = XYMakingFriendsSkillViewController.new;
- // [self addChildViewController:_skillViewController];
- // [_listView addSubview:_skillViewController.view];
- // _skillViewController.view.frame = CGRectMake(0, 20.0f, _listView.f_width, _listView.f_heigh - 20.0f);
- //
- // _listMaskView = [[XYMakingFriendsMainSkillMaskView alloc] initWithFrame:_skillViewController.view.frame];
- // _listMaskView.backgroundColor = ColorFromHexStringWithAlpha(@"#FFFFFF", 0.4);
- // [_listView addSubview:_listMaskView];
- }
- return _listView;
- }
- @end
|