解讀直播代碼中啓動廣告與引導圖的相關配置

在直播代碼中啓動廣告與引導圖是目前主流app中非常常見的功能,這裏簡單提供一個開發直播app 軟件時iOS端實現app引導圖或者啓動廣告的思路,新建一個viewcontroller來實現。
首先,appDelegate裏面稍作改動,添加如下方法

(void)openGuideVC{
    GuideVC *FirstVC = [[GuideVC alloc] init];
    UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:FirstVC];
    self.window.rootViewController = firstNav;
    [self.window makeKeyAndVisible];
}
- (void)openHomeVc{
    self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[RookieTabBarController alloc] init]];
    [self.window makeKeyAndVisible];
}

其中,第一個方法是打開直播代碼引導圖的方法,第二個是我們原本的設置的rootVC,一般是登錄頁或者首頁。現在直接調用第一個方法,先打開引導頁,在引導頁展示完成或者用戶點擊跳過之後,執行第二個方法進入app. 接下來看一下GuideVC裏面我們需要做什麼。

 //創建圖片
    image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
    image.image = [self getLaunchImage];
    image.userInteractionEnabled = YES;
    [self.view addSubview:image];
    //創建跳過按鈕
    btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:nil forState:UIControlStateNormal];
    [btn setFrame:CGRectMake(SCREEN_WIDTH - 85, _window_height - 80, 70, 25)];
    [btn addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
    [btn setTitle:@"5秒" forState:UIControlStateNormal];
    btn.titleLabel.font = SYS_Font(13);
    btn.layer.masksToBounds = YES;
    btn.layer.cornerRadius = 25.0 / 2;
    btn.layer.borderColor = [UIColor whiteColor].CGColor;
    btn.layer.borderWidth = 1.5;
    [image addSubview:btn];
    btn.userInteractionEnabled = NO;
    [self getData];`

如上,在guideVC的viewdidload中,創建一張圖片和一個跳過按鈕,如果我們要展示的圖片需要從網絡加載,那麼爲了避免加載過程中展示空白,先展示app的啓動圖,然後在getData方法裏面獲取到圖片之後,再給image賦值。然後在點擊跳過的時候,執行下面的方法打開app.

AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[appdelegate openHomeVc];

這裏是一種最簡單的情況,當然我們可以根據這種思路去實現一些更爲複雜的功能,例如在直播代碼中添加可滑動的多張圖片、添加視頻播放、添加倒計時等等,在此就不一一列舉了,這就是開發直播代碼時iOS端廣告功能的設置介紹。
聲明:本篇文章爲作者: 雲豹短視頻 原創文章,未獲得授權禁止轉載,本次轉載已獲得授權

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章