欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS實現(xiàn)動態(tài)的開屏廣告示例代碼

 更新時間:2016年09月07日 15:34:21   作者:小白yige  
啟動圖是在iOS開發(fā)過程中必不可少的一個部分,很多app在啟動圖之后會有一張自定義的開屏廣告圖,但是有的時候需要讓啟動圖看起來就是一個廣告,而且還要這個廣告里面會動,iOS的啟動圖只能是靜態(tài)的,而且固定,為了實現(xiàn)看起來的動畫效果,只能進行偽造了。下面來一起看看

一、實現(xiàn)效果圖

二、實現(xiàn)思路:

用一個固定的png圖片左啟動圖,應該和廣告視圖需要進行動畫的期初的位置一致,當啟動圖消失的時候,呈現(xiàn)出圖片,實際遇到的困難是,因為廣告圖片是從網(wǎng)絡請求加載的,當時把廣告視圖放在了請求數(shù)據(jù)的塊里面,廣告出現(xiàn)的時候會閃一下,放在外面就沒事了。

三、實現(xiàn)示例

1.廣告的頭文件

// XBAdvertView.h 
// scoreCount 
// 
// Created by 王國棟 on 15/12/22. 
// Copyright © 2015年 xiaobai. All rights reserved. 
// 
 
#import <UIKit/UIKit.h> 
@protocol XBAdvertViewDelegate <NSObject> 
/** 
 * 圖片被點擊的代理 
 */ 
-(void)adViewClick; 
@end 
@interface XBAdvertView : UIView 
 
 
@property (nonatomic,weak) id<XBAdvertViewDelegate> delegate; 
 
@property (nonatomic,strong) UIImage* adimage; 
 
@end 

2.廣告的m文件

// 
// XBAdvertView.m 
// scoreCount 
// 
// Created by 王國棟 on 15/12/22. 
// Copyright © 2015年 xiaobai. All rights reserved. 
// 
 
#import "XBAdvertView.h" 
#import "MacroDefinition.h" 
#import "UIDeviceHardware.h" 
 
 
#define kScreenW [UIScreen mainScreen].bounds.size.width 
#define kScreenH [UIScreen mainScreen].bounds.size.height 
 
#define AppViewOriginCenterY kScreenH*0.335 
#define AdvertViewRatio 0.75 
 
#define AppViewObjCenterY (kScreenH*AdvertViewRatio+35) 
 
#define AppNameObjCenterY AppViewObjCenterY+30 
#define AppNameOriginCenterY kScreenH+20 
 
#define AppImageViewW 60/0.6 
#define AppImageViewH AppImageViewW 
 
@interface XBAdvertView() 
 
///** 
// * 廣告的圖片 
// */ 
//@property (nonatomic,strong) UIImage * advertImage; 
///** 
// * app圖標 
// */ 
//@property (nonatomic,strong) UIImage* appImage; 
// 
//@property (nonatomic,strong)UILabel * appName; 
// 
///** 
// * 圖片的URL 
// */ 
//@property (nonatomic,strong) NSString* picURL; 
// 
///** 
// * 代理類去處理點擊的方法 
// */ 
 
@property (nonatomic,strong) UIImageView * advertImv; 
@property (nonatomic,strong) UIImageView * appImv; 
@property (nonatomic,strong) UILabel * appName; 
@property (nonatomic,strong) UILabel * appPinyin; 
@property (nonatomic,strong) UIImage *image; 
@end 
@implementation XBAdvertView 
 
- (void)setAdimage:(UIImage *)adimage 
{ 
 self.advertImv.image = adimage; 
  
 [UIView animateWithDuration:1.0 delay:0.5 options:UIViewAnimationOptionCurveEaseIn animations:^{ 
  UIDeviceResolution ios_Model = [UIDeviceHardware currentResolution]; //獲取設備尺寸 
  if (ios_Model==UIDevice_iPhoneHiRes||ios_Model==UIDevice_iPhoneStandardRes||ios_Model==UIDevice_iPhoneTallerHiRes){ 
   self.appImv.center = CGPointMake(self.appImv.center.x, SCREEN_HEIGHT-108+20); 
    
  }else{ 
   self.appImv.center = CGPointMake(self.appImv.center.x, SCREEN_HEIGHT-108+25); 
    
  } 
  self.appName.center= CGPointMake(self.appName.center.x, SCREEN_HEIGHT-108+self.image.size.height/2+5+15); 
  self.appImv.transform = CGAffineTransformMakeScale(0.6, 0.6); 
  self.appPinyin.center = CGPointMake(self.appPinyin.center.x,SCREEN_HEIGHT-15-10); 
  //self.appPinyin.frame = CGRectMake(0, CGRectGetMaxY(self.appName.frame)+5, SCREEN_WIDTH, 20); 
 } completion:^(BOOL finished) { 
   
  //  [UIView animateWithDuration:1.0 animations:^{ 
  // 
  //   self.advertImv.alpha=1.0f; 
  //  }]; 
  self.advertImv.alpha=1.0f; 
  [UIView animateWithDuration:3.0 animations:^{ 
    
   self.advertImv.alpha=1.0f; 
    
  } completion:^(BOOL finished) { 
    
   [NSThread sleepForTimeInterval:2.0]; 
    
   [self removeFromSuperview]; 
    
    
  }]; 
 }]; 
 
} 
- (instancetype)initWithFrame:(CGRect)frame 
{ 
  
 NSLog(@"initWithFrame"); 
 if (self = [super initWithFrame:frame]) { 
   
  //設置廣告 
  self.backgroundColor = [UIColor whiteColor]; 
  self.advertImv = [[UIImageView alloc]init]; 
  self.advertImv.backgroundColor = [UIColor grayColor]; 
  self.advertImv.contentMode=UIViewContentModeScaleToFill; 
  self.advertImv.alpha = 0;//設置為透明 
  [self addSubview:self.advertImv]; 
  //添加手勢 
  UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click)]; 
  tap.numberOfTapsRequired=1; 
  [self.advertImv addGestureRecognizer:tap]; 
   
  //設置app圖標 
  self.appImv =[[ UIImageView alloc]init]; 
  self.appImv.image = [UIImage imageNamed:@"iphone6p"]; 
  [self addSubview:self.appImv]; 
  //設置app 的名字 
  self.appName = [[UILabel alloc]init]; 
  self.appName.text = @"樂校"; 
  self.appName.font = UIFont(18); 
  self.appName.textColor = BLUE_22C4FF; 
  self.appName.textAlignment=NSTextAlignmentCenter; 
  [self addSubview:self.appName]; 
  self.appPinyin =[[UILabel alloc]init]; 
  self.appPinyin.textAlignment = NSTextAlignmentCenter; 
  self.appPinyin.font = UIFont(13); 
  self.appPinyin.textColor = BLUE_22C4FF; 
  self.appPinyin.text =@"使大學生活更精彩"; 
  [self addSubview:self.appPinyin]; 
   
  //設置廣告尺寸 
   
  UIDeviceResolution ios_Model = [UIDeviceHardware currentResolution]; //獲取設備尺寸 
  if (ios_Model==UIDevice_iPhoneHiRes||ios_Model==UIDevice_iPhoneStandardRes||ios_Model==UIDevice_iPhoneTallerHiRes){ 
   self.image = [UIImage imageNamed:@"iphone5"]; 
   self.appImv.frame = CGRectMake(0, 0, self.image.size.width, self.image.size.height); 
  }else if (ios_Model==UIDevice_iPhone6HiRes){ 
   self.image = [UIImage imageNamed:@"iphone6"]; 
   self.appImv.frame = CGRectMake(0, 0, self.image.size.width, self.image.size.height); 
  }else if (ios_Model==UIDevice_iPhone6pHiRes){ 
   self.image = [UIImage imageNamed:@"iphone6p"]; 
   self.appImv.frame = CGRectMake(0, 0, self.image.size.width, self.image.size.height); 
  } 
  //  self.appImv.frame = CGRectMake(0, 0, AppImageViewW, AppImageViewH); 
  if (ios_Model==UIDevice_iPhoneHiRes||ios_Model==UIDevice_iPhoneStandardRes){ 
   self.appImv.center = CGPointMake(kScreenW/2, AppViewOriginCenterY+5); 
  }else if (ios_Model==UIDevice_iPhone6HiRes){ 
   self.appImv.center = CGPointMake(kScreenW/2, AppViewOriginCenterY); 
  }else if (ios_Model==UIDevice_iPhoneTallerHiRes||ios_Model==UIDevice_iPhone6pHiRes){ 
   self.appImv.center = CGPointMake(kScreenW/2, AppViewOriginCenterY); 
  } 
  //設置app名字的尺寸 
  self.appName.frame =CGRectMake(0, 0, AppImageViewW, 30); 
  self.appName.center=CGPointMake(kScreenW/2, AppNameOriginCenterY); 
  //設置app拼音的尺寸 
  self.appPinyin.frame =CGRectMake(0, 0, SCREEN_WIDTH, 20); 
  self.appPinyin.center=CGPointMake(kScreenW/2, AppNameOriginCenterY+AppImageViewH/2); 
  //設置廣告尺寸 
  //self.advertImv.image = adimg; 
  self.advertImv.frame= CGRectMake(0, 0, kScreenW,kScreenH); 
   
 
 } 
 return self; 
} 
 
/** 
 * 交給代理類處理圖片點擊后的按鈕 
 */ 
-(void)click 
{ 
 if ([self.delegate respondsToSelector:@selector(adViewClick)]) { 
   
  [self.delegate adViewClick]; 
 } 
} 
/* 
// Only override drawRect: if you perform custom drawing. 
// An empty implementation adversely affects performance during animation. 
- (void)drawRect:(CGRect)rect { 
 // Drawing code 
} 
*/ 
 
@end 
[self.view setBackgroundColor:[UIColor greenColor]]; 
 
 XBAdvertView * ad = [[XBAdvertView alloc]initWithFrame:[UIScreen mainScreen].bounds]; 
 UIImage * image = [UIImage imageNamed:@"ad.jpg"]; 
 ad.adimage = image; 
 [self.view addSubview:ad]; 

四、總結

以上就是iOS實現(xiàn)動態(tài)開屏廣告的全部內容了,希望對大家學習或開發(fā)iOS能有所幫助,如果有疑問大家可以留言交流。

相關文章

  • iOS archive保存圖片到本地的方法

    iOS archive保存圖片到本地的方法

    這篇文章主要為大家詳細介紹了iOS archive保存圖片到本地的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • 淺談Xcode9 和iOS11適配和特性

    淺談Xcode9 和iOS11適配和特性

    本篇文章主要介紹了Xcode9 和iOS11適配和特性,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • 寫給iOS程序員的命令行使用秘籍

    寫給iOS程序員的命令行使用秘籍

    寫給iOS程序員的命令行使用秘籍,多事情在命令行下處理會事半功倍,所以我就iOS程序員可能會用到的功能講述一下,感興趣的小伙伴們可以參考一下
    2016-03-03
  • OC runtime學習筆記之關聯(lián)對象

    OC runtime學習筆記之關聯(lián)對象

    這篇文章主要介紹了OC runtime學習筆記之關聯(lián)對象的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2018-09-09
  • iPhoneX 各種適配記錄筆記(超全面)

    iPhoneX 各種適配記錄筆記(超全面)

    iPhone X出來之后,關于劉海的各種適配成了程序員們首要考慮的問題,下面這篇文章主要給大家介紹了關于iPhoneX 各種適配的相關資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-12-12
  • IOS開發(fā)之JSON轉PLIST實例詳解

    IOS開發(fā)之JSON轉PLIST實例詳解

    這篇文章主要介紹了IOS開發(fā)之JSON轉PLIST實例詳解的相關資料,需要的朋友可以參考下
    2016-11-11
  • scrollview tableView嵌套解決方案示例

    scrollview tableView嵌套解決方案示例

    這篇文章主要介紹了scrollview tableView嵌套解決方案示例的代碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • iOS實現(xiàn)背景滑動效果

    iOS實現(xiàn)背景滑動效果

    這篇文章主要為大家詳細介紹了iOS實現(xiàn)背景滑動效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Mac OS自帶了apache基本用法總結

    Mac OS自帶了apache基本用法總結

    這篇文章主要介紹了Mac OS自帶了apache基本用法總結,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • iOS 四種回調方法總結

    iOS 四種回調方法總結

    這篇文章主要介紹了iOS 四種回調方法總結的相關資料,需要的朋友可以參考下
    2016-10-10

最新評論