/*********************************
 *********************************
 ***当前文件为Demo界面设置，请忽略
 *********************************
 *********************************
 **/





























































































































































































































































































































#import "_.h"
#import <StipulateLanguish/StipulateLanguish.h>

@implementation ViewController (Demo)

- (BOOL)prefersStatusBarHidden {
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)prefersHomeIndicatorAutoHidden {
    return NO;
}
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
    return UIRectEdgeAll;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.demo_logs = [NSMutableArray new];
    [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(demo_loginStatusChange) name:SunAskDate.PartlyHungarianTrimmingFunHelperTransmitNineteenGravity object:nil];
    self.demo_sdk_version.text = [NSString stringWithFormat:@"SDK VERSION：%@",SunAskDate.capSphereSum];
    [self demo_addLaunchScreen];
    [self demo_addShadowAndCornerRadiusToButtons:self.view.subviews];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self demo_launchScreenAnimation];
}

- (void)demo_addLaunchScreen {
    UIStoryboard *launchStoryboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
    UIViewController *launchVC = [launchStoryboard instantiateInitialViewController];
    UIView *launchView = launchVC.view;
    launchView.frame = self.view.bounds;
    launchView.tag = 99;
    [self.view addSubview:launchView];
    self.demo_logo.hidden = YES;
}

- (void)demo_launchScreenAnimation {
    UIView *launchView = [self.view viewWithTag:99];
    UIView *logoView = [launchView viewWithTag:100];
    CGPoint youWhoCenter = [self.view convertPoint:self.demo_logo.center
                                         fromView:self.demo_logo.superview];
    UIView *movingLogo = [logoView snapshotViewAfterScreenUpdates:YES];
    movingLogo.frame = [self.view convertRect:logoView.frame fromView:logoView.superview];
    [self.view addSubview:movingLogo];
    logoView.hidden = YES;
    self.demo_login_status.hidden = YES;
    // 用dispatch_after实现真正的延迟
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:1.1
                              delay:0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
            launchView.alpha = 0;
            movingLogo.center = youWhoCenter;
            movingLogo.transform = CGAffineTransformMakeScale(self.demo_logo.bounds.size.width/movingLogo.bounds.size.width,
                                                             self.demo_logo.bounds.size.height/movingLogo.bounds.size.height);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.5 animations:^{
                self.demo_logo.hidden = NO;
                self.demo_login_status.hidden = NO;
            }];
            [launchView removeFromSuperview];
            [movingLogo removeFromSuperview];
            [self.demo_logo.layer addAnimation:[self fadeInAnimation] forKey:nil];
            // 动画结束后依次显示按钮
            [self demo_addShowAnimatioinToButtons:self.view.subviews];
        }];
    });
}

- (CABasicAnimation *)fadeInAnimation {
    CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"opacity"];
    fade.fromValue = @0;
    fade.toValue = @1;
    fade.duration = 0.3;
    fade.removedOnCompletion = NO;
    fade.fillMode = kCAFillModeForwards;
    return fade;
}

- (void)demo_loginStatusChange {
    switch (SunAskDate.pieceMapFixStatus) {
        case SubModelRemainingWarnChineseRun:
            self.demo_login_status.text = @"○ 未登录";
            self.demo_login_status.textColor = UIColor.grayColor;
            break;
        case ChannelsRareFormatsWirelessFillerArcadeResolving:
            self.demo_login_status.text = @"○ 准备登录";
            self.demo_login_status.textColor = UIColor.yellowColor;
            break;
        case BestUpsideMetalDetachWithinSlashSymmetric:
            self.demo_login_status.text = @"○ 登录中...";
            self.demo_login_status.textColor = UIColor.blueColor;
            break;
        case DecideIntervalCutterLocatorHigherFat:
            self.demo_login_status.text = @"● 已登录";
            self.demo_login_status.textColor = UIColor.greenColor;
            break;
    }
}

- (void)demo_addShadowAndCornerRadiusToButtons:(NSArray *)subviews {
    for (UIView *friends in subviews) {
        [self demo_addShadowAndCornerRadiusToButtons:friends.subviews];
        if ([friends isKindOfClass:[UIButton class]]) {
            friends.layer.cornerRadius = 5.0;
            friends.layer.shadowColor = [UIColor lightGrayColor].CGColor;
            friends.layer.shadowOffset = CGSizeMake(0, 3);
            friends.layer.shadowOpacity = 0.5;
            friends.layer.shadowRadius = 4.0;
            friends.clipsToBounds = NO;
            friends.alpha = 0;
        }
   }
}

- (void)demo_addShowAnimatioinToButtons:(NSArray *)subviews {
    static NSTimeInterval baseDelay = 0.08;
    static NSTimeInterval animDuration = 0.25;
    __block NSInteger btnIndex = 0;
    for (UIView *friends in subviews) {
        [self demo_addShowAnimatioinToButtons:friends.subviews];
        if ([friends isKindOfClass:[UIButton class]]) {
            friends.alpha = 0;
            [UIView animateWithDuration:animDuration
                                  delay:btnIndex * baseDelay
                                options:UIViewAnimationOptionCurveEaseInOut
                             animations:^{
                friends.alpha = 1;
            } completion:nil];
            btnIndex++;
        }
    }
}

- (void)demo_log:(NSString *)logMessage {
    NSLog(@"%@",logMessage);
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.demo_logs addObject:logMessage];
        NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:self.demo_logs.count - 1 inSection:0];
        [self.demo_tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.demo_tableView scrollToRowAtIndexPath:newIndexPath
                             atScrollPosition:UITableViewScrollPositionBottom
                                     animated:YES];
    });
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.demo_logs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *logo = [tableView dequeueReusableCellWithIdentifier:@"LogCell" forIndexPath:indexPath];
    logo.textLabel.text = self.demo_logs[indexPath.row];
    logo.textLabel.numberOfLines = 0;
    return logo;
}
@end
