• 启动图后面 添加有倒计时的广告图


    今天闲来无事,看到很多APP在启动图后面添加了广告图,今天就动手做了一下,

    刚开始,打算用通知在APPdelegate中添加这个图片,但是尝试后发现,效果不是很理想;就在rootVC中进行操作了

    直接上代码:

    -(void)gotoImage
    {
         self.window =  [[UIApplication sharedApplication].delegate window];
        
        self.mianImageview = [[UIImageView alloc]init];
        _mianImageview.image = [UIImage imageNamed:@"mianimage.jpg"];
        _mianImageview.frame = _window.bounds;
        _mianImageview.tag = 100;
        _mianImageview.userInteractionEnabled = YES;
        [_window addSubview:_mianImageview];
        
        UITapGestureRecognizer *pan = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickmianimage)];
        pan.numberOfTouchesRequired = 1;
        pan.numberOfTapsRequired = 1;
        [_mianImageview addGestureRecognizer:pan];
        
        
        //创建UILabel 添加到当前view
        _labelText=[[UILabel alloc]initWithFrame:CGRectMake(40, MYScreenH-100, 80, 30)];
        _labelText.backgroundColor = [UIColor redColor];
        _labelText.textAlignment = NSTextAlignmentCenter;
        [_mianImageview addSubview:_labelText];
        
        //设置倒计时总时长
        _secondsCountDown = 2;//60秒倒计时
        //开始倒计时
        _countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES]; //启动倒计时后会每秒钟调用一次方法 timeFireMethod
        
        //设置倒计时显示的时间
        _labelText.text=[NSString stringWithFormat:@"%ldS",(long)_secondsCountDown];
        
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            for (UIView *subviews in [_window subviews]) {
                if (subviews.tag ==100) {
        
                        [UIView animateWithDuration:1.0 animations:^{
                            
                            CGPoint center = _mianImageview.center;
                            _mianImageview.width = 10000;
                            _mianImageview.height = 10000;
                            _mianImageview.center = center;
                            
                            subviews.alpha = 0;
                            
                        } completion:^(BOOL finished) {
                            
                            [subviews removeFromSuperview];
                            
                        }];
                    }
                
                }
            
    
        });
    }

    这个方法在viewdidload:中调用;

    倒计时的方法,每秒就调用一次:

    -(void)timeFireMethod{
        //倒计时-1
        _secondsCountDown--;
        //修改倒计时标签现实内容
        _labelText.text=[NSString stringWithFormat:@"%ldS",(long)_secondsCountDown];
        //当倒计时到0时,做需要的操作,比如验证码过期不能提交
        if(_secondsCountDown==-1){
    
            [_countDownTimer invalidate];
            [_labelText removeFromSuperview];
        }
    }

    下面的这个方法是这个广告图的点击方法,一般是跳到广告详情的,我在这里只是提前隐藏广告图

    -(void)clickmianimage
    {
            for (UIView *subviews in [_window subviews]) {
                if (subviews.tag ==100) {
                    
                    [UIView animateWithDuration:0.5 animations:^{
                        
                        CGPoint center = _mianImageview.center;
                        _mianImageview.width = 10000;
                        _mianImageview.height = 10000;
                        _mianImageview.center = center;
                        
    
                        subviews.alpha = 0;
                        
                    } completion:^(BOOL finished) {
                        
                        [subviews removeFromSuperview];
                        
                    }];
                }
                
            }
        
    
    }

    如果大神发现有什么问题,求在评论中指出:谢谢指教!

  • 相关阅读:
    禅道项目管理系统自定义菜单相关
    2015年技术方向转变计划
    LinuxMint 17.1 Cinnamon桌面窗口焦点bug
    通过指定函数/方法形参类型提高PHP代码可靠性
    Apache+Mod_Python配置
    JPHP最新进展 v0.6
    “领域驱动开发”实例之旅(1)--不一样的开发模式
    Key/Value之王Memcached初探:二、Memcached在.Net中的基本操作
    哈希值 是什么?哈希值是什么东西啊?具体怎么识别?怎么用?
    TortoiseGit 使用教程
  • 原文地址:https://www.cnblogs.com/liuwenqiang/p/5653020.html
Copyright © 2020-2023  润新知