iOS歡迎介面Launch Screen動態載入廣告

來源:互聯網
上載者:User

標籤:

有許多應用程式在開啟的時候,歡迎介面會載入一張連網擷取的廣告圖片或者顯示一組動畫,這樣的效果是如何做到的呢?下面給大家介紹一種簡單的實現載入廣告的方式。

程式運行起來,歡迎介面之後,會進入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];}

iOS歡迎介面Launch Screen動態載入廣告

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.