国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

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

2020-07-26 03:14:44
字體:
供稿:網(wǎng)友

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

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

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

三、實(shí)現(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> /**  * 圖片被點(diǎn)擊的代理  */ -(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圖標(biāo) // */ //@property (nonatomic,strong) UIImage* appImage; // //@property (nonatomic,strong)UILabel * appName; // ///** // * 圖片的URL // */ //@property (nonatomic,strong) NSString* picURL; // ///** // * 代理類去處理點(diǎn)擊的方法 // */  @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]; //獲取設(shè)備尺寸   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]) {      //設(shè)置廣告   self.backgroundColor = [UIColor whiteColor];   self.advertImv = [[UIImageView alloc]init];   self.advertImv.backgroundColor = [UIColor grayColor];   self.advertImv.contentMode=UIViewContentModeScaleToFill;   self.advertImv.alpha = 0;//設(shè)置為透明   [self addSubview:self.advertImv];   //添加手勢(shì)   UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click)];   tap.numberOfTapsRequired=1;   [self.advertImv addGestureRecognizer:tap];      //設(shè)置app圖標(biāo)   self.appImv =[[ UIImageView alloc]init];   self.appImv.image = [UIImage imageNamed:@"iphone6p"];   [self addSubview:self.appImv];   //設(shè)置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 =@"使大學(xué)生活更精彩";   [self addSubview:self.appPinyin];      //設(shè)置廣告尺寸      UIDeviceResolution ios_Model = [UIDeviceHardware currentResolution]; //獲取設(shè)備尺寸   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);   }   //設(shè)置app名字的尺寸   self.appName.frame =CGRectMake(0, 0, AppImageViewW, 30);   self.appName.center=CGPointMake(kScreenW/2, AppNameOriginCenterY);   //設(shè)置app拼音的尺寸   self.appPinyin.frame =CGRectMake(0, 0, SCREEN_WIDTH, 20);   self.appPinyin.center=CGPointMake(kScreenW/2, AppNameOriginCenterY+AppImageViewH/2);   //設(shè)置廣告尺寸   //self.advertImv.image = adimg;   self.advertImv.frame= CGRectMake(0, 0, kScreenW,kScreenH);      }  return self; }  /**  * 交給代理類處理圖片點(diǎn)擊后的按鈕  */ -(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]; 

四、總結(jié)

以上就是iOS實(shí)現(xiàn)動(dòng)態(tài)開屏廣告的全部?jī)?nèi)容了,希望對(duì)大家學(xué)習(xí)或開發(fā)iOS能有所幫助,如果有疑問大家可以留言交流。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 朝阳区| 开化县| 安岳县| 施甸县| 武乡县| 故城县| 贵州省| 泾源县| 祁连县| 桃源县| 徐州市| 麻阳| 铜陵市| 太和县| 新源县| 双鸭山市| 秦皇岛市| 林州市| 临澧县| 西畴县| 当涂县| 栾城县| 青州市| 安丘市| 左云县| 旬邑县| 祁东县| 万载县| 普宁市| 瑞金市| 万州区| 永靖县| 古田县| 凤翔县| 洞头县| 阳信县| 穆棱市| 新野县| 沂水县| 斗六市| 吉隆县|