开发直播app 软件时iOS端广告功能设置

在直播app 软件中启动广告与引导图是目前主流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];

这里是一种最简单的情况,当然我们可以根据这种思路去实现一些更为复杂的功能,例如添加可滑动的多张图片、添加视频播放、添加倒计时等等,在此就不一一列举了,这就是开发直播app 软件时iOS端广告功能的设置介绍。
声明:本篇文章为小编原创文章,转载请注明出处及作者。

猜你喜欢

转载自blog.51cto.com/14302750/2386187
今日推荐