【iOS_Development】广告图的添加

广告图的添加

  • 问题描述:在启动图上添加不固定文字(网络请求获取的),或者广告图。

  • 直接上一帧未✂️ oh yeah 版的效果图吧!

  • 解决办法

1. 自己建立一个AdvertisementViewController,在AdvertisementViewController里实现自己想要效果,例如添加背景图片 && logo && 展示文字的Label等,viewdidload中调用adStart代码如下:
- (void)adStart {
    // 背景图片
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    imageView.image = [UIImage imageNamed:@"launchpage_BackgroundImage"];
    [self.view addSubview:imageView];

    // 添加Logo
    UIImage *logoIm = [UIImage imageNamed:@"launchpage_logo"];
    CGFloat logoImWidth = logoIm.size.width;
    CGFloat logImHeight = logoIm.size.height;

    UIImageView *logoIV = [[UIImageView alloc] initWithFrame:CGRectMake((FrameW - logoImWidth)/2, FrameH - 84/2*WidthScale375 - logImHeight, logoImWidth, logImHeight)];
    logoIV.image = logoIm;
    [self.view addSubview:logoIV];

    // 添加label
    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(5, FrameH - 15 - 40/2*WidthScale375, FrameW - 10, 15)];
    lab.text = @"要展示的文字";
    lab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:lab];

    // 初始化定时器
    _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(adChangeNextViewController) userInfo:nil repeats:NO];
}

/** 定时展示完页面后触发方法 */
- (void)adChangeNextViewController {
    [((AppDelegate *)([UIApplication sharedApplication].delegate)) showNextViewController];
}
2. 修改appDelegate

(1) appDelegate.h中暴露方法

/** 模拟启动页回来调用的方法 */
- (void)showNextViewController;

(2)appDelegate.m 在didFinishLaunchingWithOptions方法中进行相关更改

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 // 模拟启动页
    AdvertisementViewController *StartFigure = [[AdvertisementViewController alloc] init];
    self.window.rootViewController = StartFigure;
    [self.window makeKeyAndVisible];
    return YES;
}

/** 模拟启动页回来调用的方法 */
- (void)showNextViewController {
    // 模拟启动图结束了,跳这里,这里面正常处理,例如:改走引导页,或者TabBarController或者登录页面等等,自己决定啦。。。
    self.window.rootViewController= 引导页/TabBarController/登录页面;
}
3. 注意事项:要想实现没有背景闪动的效果可以将 1 中创建的AdvertisementViewController的背景图片设为和启动图一样的图片,前提是启动图较为干净,这样就能很好的实现启动图和自己写AdvertisementViewController之间界面切换的无痕性。
4. Plus:只要上述的效果可以实现,同样的对于我们来说实现启动页之后的动画效果 || 轮播图效果等等也就不是问题啦,只需在1 中创建的AdvertisementViewController进行相应的实现即可啦!

GitHub地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值