zoukankan      html  css  js  c++  java
  • iOS欢迎界面Launch Screen动态加载广告

    有许多应用程序在打开的时候,欢迎界面会加载一张连网获取的广告图片或者显示一组动画,这样的效果是如何做到的呢?下面给大家介绍一种简单的实现加载广告的方式。

    程序运行起来,欢迎界面之后,会进入AppDelegate,因此我们可以在application: didFinishLaunchingWithOptions:添加代码完成想要的效果。连网获取图片可以用第三方SDWebImage实现,所以需要先将第三方文件夹导入。因为显示广告的页面是在欢迎界面基础上显示的,因此可以直接利用LaunchScreen.xib中得view,在上面添加一个UIImageView显示图片,然后将其加在window上,并显示在最上层。广告图片显示之后,再将view移除掉,显示程序的主界面。代码如下所示:

    #import "AppDelegate.h"
    #import "UIImageView+WebCache.h"
    @interface AppDelegate ()
    @property (strong, nonatomic) UIView *lunchView;
    @end
    
    @implementation AppDelegate
    @synthesize lunchView;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        [self.window makeKeyAndVisible];
    
        lunchView = [[NSBundle mainBundle ]loadNibNamed:@"LaunchScreen" owner:nil options:nil][0];
        lunchView.frame = CGRectMake(0, 0, self.window.screen.bounds.size.width, self.window.screen.bounds.size.height);
        [self.window addSubview:lunchView];
    
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 50, 320, 300)];
        NSString *str = @"http://www.jerehedu.com/images/temp/logo.gif";
        [imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"default1.jpg"]];
        [lunchView addSubview:imageV];
    
        [self.window bringSubviewToFront:lunchView];
    
        [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(removeLun) userInfo:nil repeats:NO];
    
        return YES;
    }
    
    -(void)removeLun
    {
        [lunchView removeFromSuperview];
    }
  • 相关阅读:
    HDU 3853:LOOPS(概率DP)
    HDU 4405:Aeroplane chess(概率DP入门)
    中国剩余定理模板
    HDU 5768:Lucky7(中国剩余定理 + 容斥原理)
    欧几里得和拓展欧几里得模板
    HDU 5025:Saving Tang Monk(BFS + 状压)
    HDU 1728:逃离迷宫(BFS)
    HDU 5795:A Simple Nim(博弈)
    HDU 5724:Chess(博弈 + 状压)
    HDU 5818:Joint Stacks(stack + deque)
  • 原文地址:https://www.cnblogs.com/songxing10000/p/4712268.html
Copyright © 2011-2022 走看看