標籤:
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