123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- //
- // SimulationWaitExamController.m
- // MusicGradeExam
- //
- // Created by Kyle on 2020/9/21.
- // Copyright © 2020 DayaMusic. All rights reserved.
- //
- #import "SimulationWaitExamController.h"
- #import "WaitExamBodyView.h"
- #import "OnlineRoomManager.h"
- #import "ExamGuideViewController.h"
- #import "KSGuideMaskView.h"
- #import "UserInfoManager.h"
- #import "WaitExamBottomView.h"
- #import "AppDelegate.h"
- #define BOTTOMVIEW_HEIGHT (150)
- @interface SimulationWaitExamController ()<UIScrollViewDelegate>
- @property (nonatomic, strong) WaitExamBodyView *bodyView;
- @property (nonatomic, strong) OnlineRoomManager *classManager;
- @property (nonatomic, assign) BOOL cancleRequest;
- @property (nonatomic, strong) WaitExamBottomView *bottomView;
- @property (nonatomic, assign) BOOL hasShowTopTips;
- @property (nonatomic, assign) BOOL hasShowBottomTips;
- @property (nonatomic, strong) NSTimer *timeTimer;
- @end
- @implementation SimulationWaitExamController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"直播模拟考试"];
- self.view.backgroundColor = HexRGB(0xf3f4f8);
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backLoginView) name:@"backLoginView" object:nil];
- [self configUI];
- self.sourceModel.desc = [self.sourceModel.desc replaceAll:@"\\n" WithString:@"\n"];
- [self evaluateSource];
- }
- // 被挤掉
- - (void)backLoginView {
- _cancleRequest = YES;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
- if(@available(iOS 13.0, *)){
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
- }
- if (_cancleRequest) {
- _cancleRequest = NO;
- [KSRequestManager logoutAction];
- return;
- }
- [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- if (_hasShowTopTips == NO) {
- [self addIntroduceView];
- }
- }
- - (void)addIntroduceView {
- _hasShowTopTips = YES;
- CGRect rect1 = [self.bodyView convertRect:self.bodyView.signButton.frame toView:[UIApplication sharedApplication].keyWindow];
- rect1.origin.y += 8;
- rect1.origin.x += 8;
- rect1.size.width -= 16;
- rect1.size.height -= 16;
-
- UIBezierPath *pathOne = [UIBezierPath bezierPathWithOvalInRect:rect1];
- CGRect rect2 = [self.bodyView convertRect:self.bodyView.examMessageView.frame toView:[UIApplication sharedApplication].keyWindow];
- UIBezierPath *pathSecond = [UIBezierPath bezierPathWithRect:rect2];
-
- CGFloat height = CGRectGetHeight(self.bodyView.frame);
- NSArray *tipsArray = @[@"考场开启后,才可已进行签到,签到后排考", @"这是您的考试信息"];
- NSArray *bezierArray = @[pathOne,pathSecond];
- if (height == kScreenHeight - kTabBarHeight - iPhoneXSafeBottomMargin - BOTTOMVIEW_HEIGHT) {
- CGRect rect3 = [self.bodyView convertRect:self.bodyView.tipsView.frame toView:[UIApplication sharedApplication].keyWindow];
- UIBezierPath *pathThree = [UIBezierPath bezierPathWithRect:rect3];
- tipsArray = @[@"考场开启后,才可已进行签到,签到后排考", @"这是您的考试信息",@"请认真阅读考试注意事项"];
- bezierArray = @[pathOne,pathSecond,pathThree];
- }
-
- KSGuideMaskView *guideView = [[KSGuideMaskView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
- [guideView addTips:tipsArray transparentRect:bezierArray shaperLayerIndex:0];
- if (tipsArray.count == 2) {
- [guideView completeCallback:^{
- [self scrollToBottom];
- }];
- }
- [guideView showMaskViewInView:nil];
- }
- - (void)showBottomTips {
- _hasShowBottomTips = YES;
- NSArray *tipsArray = @[@"请认真阅读考试注意事项"];
- CGRect rect3 = [self.bodyView convertRect:self.bodyView.tipsView.frame toView:[UIApplication sharedApplication].keyWindow];
- UIBezierPath *pathThree = [UIBezierPath bezierPathWithRect:rect3];
- NSArray *bezierArray = @[pathThree];
- KSGuideMaskView *guideView = [[KSGuideMaskView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
- [guideView addTips:tipsArray transparentRect:bezierArray shaperLayerIndex:-1];
- [guideView showMaskViewInView:nil];
- }
- - (void)evaluateSource {
- [self.bodyView configMessageSource:self.sourceModel];
- [self.bottomView configMessageSource:self.sourceModel];
- [self configViewHeight];
-
- if (USER_MANAGER.needConnect == NO) {
- if (![NSString isEmptyString:self.sourceModel.examStartTime]) {
- NSString *examDay = [[self.sourceModel.examStartTime componentsSeparatedByString:@" "] firstObject];
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- [formatter setDateFormat:@"yyyy-MM-dd"];
- formatter.timeZone = [NSTimeZone systemTimeZone];
- NSDate *currentDate = [NSDate date];
- NSString *currentDay = [formatter stringFromDate:currentDate];
- if ([examDay isEqualToString:currentDay]) { // 如果今天有考试,IM建立连接
- [self configIMConnection];
- }
- }
- }
- }
- - (void)configIMConnection {
- [USER_MANAGER connectRongCloud];
- USER_MANAGER.needConnect = YES;
- }
- - (void)configViewHeight {
- CGFloat tipsHeight = [self.bodyView configTipsHeight:self.sourceModel.desc];
- CGFloat viewHeight = 206 + 200 + 19 + tipsHeight + 15;
- viewHeight = viewHeight > kScreenHeight - kTabBarHeight - iPhoneXSafeBottomMargin ? viewHeight : kScreenHeight - kTabBarHeight - iPhoneXSafeBottomMargin;
- self.bodyView.frame = CGRectMake(0, 0, kScreenWidth, viewHeight);
- [self.scrollView setContentSize:CGSizeMake(kScreenWidth, viewHeight)];
- }
- - (void)configUI {
- self.scrollView.backgroundColor = HexRGB(0xf3f4f8);
- self.scrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTabBarHeight - iPhoneXSafeBottomMargin - BOTTOMVIEW_HEIGHT);
- self.scrollView.delegate = self;
- self.scrollView.bounces = NO;
- _bodyView = [WaitExamBodyView shareInstance];
- CGFloat viewHeight = 206 + 200 + 19 + 204 + 15;
- viewHeight = viewHeight > kScreenHeight - kTabBarHeight - iPhoneXSafeBottomMargin - BOTTOMVIEW_HEIGHT ? viewHeight : kScreenHeight - kTabBarHeight - iPhoneXSafeBottomMargin - BOTTOMVIEW_HEIGHT;
- _bodyView.frame = CGRectMake(0, 0, kScreenWidth, viewHeight);
- MJWeakSelf;
- [_bodyView operationCallback:^(JOINROOMACTION action, TicketDetailModel * _Nullable source) {
- [weakSelf opreationAction:action source:source];
- }];
- [self.scrollView addSubview:_bodyView];
- [self.scrollView setContentSize:CGSizeMake(kScreenWidth, viewHeight)];
-
- _bottomView = [WaitExamBottomView shareInstance];
- _bottomView.isSimulation = YES;
- _bottomView.frame = CGRectMake(0, CGRectGetMaxY(self.scrollView.frame), kScreenWidth, BOTTOMVIEW_HEIGHT);
- [_bottomView operationCallback:^(JOINROOMACTION action, TicketDetailModel * _Nullable source) {
- [weakSelf opreationAction:action source:source];
- }];
- [self.view addSubview:_bottomView];
- }
- - (void)opreationAction:(JOINROOMACTION)action source:(TicketDetailModel *)source {
- switch (action) {
- case JOINROOMACTION_SIGN: // 签到
- {
- [self signAction];
- }
- break;
- case JOINROOMACTION_GUIDE: // 引导页
- {
- ExamGuideViewController *guideVC = [[ExamGuideViewController alloc] init];
- [self.navigationController pushViewController:guideVC animated:YES];
- }
- break;
- case JOINROOMACTION_JOIN: // 加入房间
- {
- if (self.sourceModel.classroomSwitch == 1) {
- NSString *roomId = [NSString stringWithFormat:@"%.0f", source.examRegistrationId];
- [self joinRoomAction:roomId];
- }
- }
- break;
- default:
- break;
- }
- }
- #pragma mark ----- 签到
- - (void)signAction {
- MJWeakSelf;
- [self KSShowMsg:@"签到成功" promptCompletion:^{
- weakSelf.sourceModel.finishedExam = 2;
- weakSelf.sourceModel.signInTime = @"2020-09-22 18:00:00";
- // 滑动到底部
- [weakSelf scrollToBottom];
- // 开始排队
- [weakSelf evaluateSource];
- [weakSelf countWaitList];
- }];
- }
- // 开启定时器
- - (void)countWaitList {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.timeTimer setFireDate:[NSDate distantPast]];
- });
- }
-
- - (void)scrollToBottom {
- CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
- [self.scrollView setContentOffset:bottomOffset animated:YES];
- }
- #pragma mark ----- 加入房间
- - (void)joinRoomAction:(NSString *)roomId {
- [self.classManager joinRoomWithId:roomId subjectName:self.sourceModel.subjectName inViewController:self];
- }
- - (OnlineRoomManager *)classManager {
- if (!_classManager) {
- _classManager = [[OnlineRoomManager alloc] init];
- }
- return _classManager;
- }
- - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
- CGPoint offset = scrollView.contentOffset;
- CGRect bounds = scrollView.bounds;
- CGSize size = scrollView.contentSize;
- UIEdgeInsets inset = scrollView.contentInset;
- CGFloat currentOffset = offset.y + bounds.size.height - inset.bottom;
- CGFloat maximumOffset = size.height;
- if((maximumOffset - currentOffset) < 40.0) {
- if (_hasShowBottomTips == NO) {
- [self showBottomTips];
- }
- }
- }
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- CGPoint offset = scrollView.contentOffset;
- CGRect bounds = scrollView.bounds;
- CGSize size = scrollView.contentSize;
- UIEdgeInsets inset = scrollView.contentInset;
- CGFloat currentOffset = offset.y + bounds.size.height - inset.bottom;
- CGFloat maximumOffset = size.height;
- if((maximumOffset - currentOffset) < 40.0) {
- if (_hasShowBottomTips == NO) {
- [self showBottomTips];
- }
- }
- }
- - (void)timeFunction:(NSTimer *)timer {
- if (self.sourceModel.waitNum > 0) {
- self.sourceModel.waitNum--;
- }
- else {
- [self stopTimer];
- self.sourceModel.classroomSwitch = 1;
- }
- [self.bottomView configMessageSource:self.sourceModel];
- }
- - (void)stopTimer {
- [self.timeTimer setFireDate:[NSDate distantFuture]];
- if (self.timeTimer.valid) {
- [self.timeTimer invalidate];
- self.timeTimer = nil;
- }
- }
- - (NSTimer *)timeTimer {
- if (_timeTimer == nil) {
-
- _timeTimer = [NSTimer scheduledTimerWithTimeInterval:5
- target:self
- selector:@selector(timeFunction:)
- userInfo:nil
- repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:_timeTimer forMode:NSRunLoopCommonModes];
- }
-
- return _timeTimer;
- }
- - (void)dealloc {
- [self stopTimer];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|