【iOS_Development】廣告圖的添加

廣告圖的添加

  • 問題描述:在啟動圖上添加不固定文字(網絡請求獲取的),或者廣告圖。

  • 直接上一幀未?? oh yeah 版的效果圖吧!


  • 解決辦法

<span id = "No.1">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主頁

CSDN Blog

Email:jinjob@icloud.com

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容