應用程式程式啟動時載入廣告 ---ios

來源:互聯網
上載者:User

標籤:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.