• 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;

    }

    挥毫泼墨,书写人生篇章
  • 相关阅读:
    WPS 模拟手写签名
    Flask 正则匹配路由、异常
    FLASK 加载配置、简单传参调用、指定请求方式、返回json、网页跳转(也可以自己的视图函数)、自定义状态码
    python IDLE 自动提示功能
    PYQT设计无边框窗体
    PYQT窗口居中
    PYQT窗口托盘目录
    PYQT窗口风格
    PYQT窗口可视化编程
    PYQT控件使用
  • 原文地址:https://www.cnblogs.com/Jusive/p/6089969.html
Copyright © 2020-2023  润新知