码迷,mamicode.com
首页 > 移动开发 > 详细

应用程序程序启动时加载广告 ---ios

时间:2016-07-10 21:33:12      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

app 在启动的时候会加载启动图片,我们怎么样去做一个广告页面呢?

思路:在启动完毕后,创建一个加载广告的控制器,然后等广告结束后,我们在去加载主框架内容

如图:

技术分享

首先我们先创建一个AD的控制器

@interface ABADViewController ()
@property (weak, nonatomic) IBOutlet UIButton *ADJumpBtn;
//跳过 按钮
@property (weak, nonatomic) IBOutlet UIImageView *ADImageView;
//加载界面的图片
@property (weak, nonatomic) IBOutlet UIView *ADView;
@property (nonatomic, weak) UIImageView *imageView;
//加载广告的图片
@property (nonatomic, strong) ABADModel *model;
@property (nonatomic, weak) NSTimer *timer;


@end

@implementation ABADViewController
- (UIImageView *)imageView{
    if (_imageView == nil) {
        UIImageView *imageView = [[UIImageView alloc] init];
        _imageView = imageView;
        [self.ADView addSubview:imageView];
        _imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
//添加手势
        [imageView addGestureRecognizer:tap];
        
    }
    return _imageView;
}
- (void)tap{
    UIApplication *app = [UIApplication sharedApplication];
    if ([app canOpenURL:[NSURL URLWithString:@"http://sina.cn/?wm=4007"]]) {

        [app openURL:[NSURL URLWithString:@"http://sina.cn/?wm=4007"]];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setLau];
    [self loadData];
    _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeTime) userInfo:nil repeats:YES];
//添加定时器,倒数时间

}
- (void)setLau{
    self.ADImageView.image = [UIImage imageNamed:@"LaunchImage-568h"];

}
- (void)loadData{
  //利用sdImage框架异步下载广告界面 赋值与self.imageView  
}
- (IBAction)ADBtnClick:(id)sender {
    UIApplication *app = [UIApplication sharedApplication];
    app.keyWindow.rootViewController = [[ABTBController alloc] init];
    [_timer invalidate];
//销毁定时器,否则不会释放
}
- (void)changeTime{
    static int time =3;
    if (time  <= 0 ){
        [self ADBtnClick:nil];
    }
    time--;
    NSString *str = [NSString stringWithFormat:@"跳过 %d秒",time];
    [self.ADJumpBtn setTitle:str forState:UIControlStateNormal];
//利用定时器倒数时间,时间结束触发按钮事件
}

  

 

应用程序程序启动时加载广告 ---ios

标签:

原文地址:http://www.cnblogs.com/beNabenen/p/5658325.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!