标签:
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]; //利用定时器倒数时间,时间结束触发按钮事件 }
标签:
原文地址:http://www.cnblogs.com/beNabenen/p/5658325.html