zoukankan      html  css  js  c++  java
  • iOS app进入后台遮罩的实现

    - (void)applicationDidEnterBackground:(UIApplication *)application {

        if (yesLogin) {

            dispatch_async(dispatch_get_main_queue(), ^{

                [self add];

                yesLogin = YES;

            });

        }

        NSLog(@"self.EffectScenView.subviews%@",self.EffectScenView.subviews);

            self.date = [NSDate date];

        NSLog(@"self.date%@",self.date);

        NSLog(@"进入后台---applicationDidEnterBackground----"); //进入后台

    }

    - (void)applicationDidBecomeActive:(UIApplication *)application {

        dispatch_async(dispatch_get_main_queue(), ^{

            [self remoScenView];

            NSLog(@"yesLogin%hhd",yesLogin);

            NSDate *changeDate = [NSDate date];

            if ([self.date isThisTodayHour] && yesLogin) {

                NSLog(@"++++++++++++++++++++++++++++++++");

                if ( [changeDate deltaFrom:self.date].minute >= 15) {

                 NSLog(@"11111111111111+");

                    dispatch_async(dispatch_get_main_queue(), ^{

                        LoginViewController *logn = [LoginViewController new];

                        [UIApplication sharedApplication].keyWindow.rootViewController = logn;

                    });

                }

            }

            if ([self.date isThisTodayPreHour] && yesLogin) {

                NSCalendar *cal = [NSCalendar currentCalendar];

                unsigned int unitFlags = kCFCalendarUnitYear |kCFCalendarUnitMonth | NSCalendarUnitDay |NSCalendarUnitHour | NSCalendarUnitMinute;

                NSDateComponents *dd = [cal components:unitFlags fromDate:self.date];

                NSInteger minute = [dd minute];

                if ([changeDate deltaFrom:self.date].minute +(60 -minute) >= 15) {

                    dispatch_async(dispatch_get_main_queue(), ^{

                        LoginViewController *logn = [LoginViewController new];

                        [UIApplication sharedApplication].keyWindow.rootViewController = logn;

                    });

                }

            }

            NSLog(@"进入前台---applicationDidBecomeActive----");//进入前台

        });

    }

     //添加window 由于我的项目中还有其他的弹出window,为了避免冲突所以这里+2

    - (void)add {

        self.EffectScenView.windowLevel = UIWindowLevelAlert+2;

        [self.EffectScenView makeKeyAndVisible];

    }

    //移除window

    -(void)remoScenView{

        dispatch_async(dispatch_get_main_queue(), ^{

            self.EffectScenView.hidden=YES;

            self.EffectScenView.rootViewController = nil;

            [self.EffectScenView resignKeyWindow];

            [self.EffectScenView removeFromSuperview];

        });

    }

    //判断是否是前一个小时

    - (BOOL)isThisTodayPreHour

    {

        //日期格式化类

        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

        formatter.dateFormat = @"yyyy-MM-dd";

        NSDate *nowDate = [formatter dateFromString:[formatter stringFromDate:[NSDate date]]];

        NSDate *selfDate = [formatter dateFromString:[formatter stringFromDate:self]]; //self 表示的是调用当前方法的对象

        

        NSCalendar *calendar = [NSCalendar currentCalendar];

        NSDateComponents *compt = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour fromDate:selfDate toDate:nowDate options:0];

        //时间差是一天

        return compt.year == 0 && compt.month == 0 && compt.day == 0 && compt.hour == 1;

        

    }

     //判断是否是当前这个小时

    - (BOOL)isThisTodayHour

    {

        NSCalendar *calendar = [NSCalendar currentCalendar];

        NSCalendarUnit unite = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour ;

        NSDateComponents *nowCmpts = [calendar components:unite fromDate:[NSDate date]];

        NSDateComponents *selfCmpt = [calendar components:unite fromDate:self];

        return nowCmpts.year == selfCmpt.year

        && nowCmpts.month == selfCmpt.month

        && nowCmpts.day == selfCmpt.day && nowCmpts.hour == selfCmpt.hour;

    }

    挥毫泼墨,书写人生篇章
  • 相关阅读:
    BZOJ 3881: [Coci2015]Divljak
    BZOJ 2434: [Noi2011]阿狸的打字机
    BZOJ 2580: [Usaco2012 Jan]Video Game
    BZOJ 3940: [Usaco2015 Feb]Censoring
    BZOJ 3942: [Usaco2015 Feb]Censoring
    PTA L2-002 链表去重 团体程序设计天梯赛-练习集
    PTA L2-001 紧急救援-最短路(Dijkstra)多条最短路找最优解并输出路径 团体程序设计天梯赛-练习集
    PTA L1-020 帅到没朋友 团体程序设计天梯赛-练习集
    Codeforces 429 B. Working out-dp( Codeforces Round #245 (Div. 1))
    HDU 6467.简单数学题-数学题 (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)
  • 原文地址:https://www.cnblogs.com/Jusive/p/6089969.html
Copyright © 2011-2022 走看看