One, the realization of the effect chart
Second, the realization of ideas:
With a fixed PNG picture, the left boot map should be in line with the initial position of the ad view that needs to be animated, when the start diagram disappears, presents the picture, actually encounters the difficulty is, because the advertisement picture is from the network request loading, at that time put the advertisement view in the request data block inside, the advertisement appears when will Flash, It's okay to leave it outside.
III. implementation Examples
1. Advertising header File
XBAdvertView.h
//Scorecount////
Created by Wangguodong on 15/12/22.
COPYRIGHT©2015 year Xiaobai. All rights reserved.
#import <UIKit/UIKit.h>
@protocol xbadvertviewdelegate <NSObject>
/**
* The image is clicked the Agent
* *
-(void) Adviewclick;
@end
@interface xbadvertview:uiview
@property (nonatomic,weak) id<xbadvertviewdelegate> delegate;
@property (Nonatomic,strong) uiimage* adimage;
2. The advertisement of the M file
XBADVERTVIEW.M//Scorecount////Created by Wangguodong on 15/12/22. COPYRIGHT©2015 year 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 AppName Objcentery appviewobjcentery+30 #define Appnameorigincentery kscreenh+20 #define APPIMAGEVIEWW 60/0.6 #define AppImag EVIEWH appimagevieww @interface Xbadvertview ()///**//* Advertising Pictures////@property (Nonatomic,strong) uiimage * AD
Vertimage;
* *//* app icon/////@property (Nonatomic,strong) uiimage* appimage;
@property (Nonatomic,strong) Uilabel * APPNAME;
* *//* Picture URL/////@property (Nonatomic,strong) nsstring* Picurl; * *//* Agent class to deal with the click of the method//@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]; Get device size 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.alph
a=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]) {//Set ad Self.backgroundcolor = [Uicolor Whitecolor];
SELF.ADVERTIMV = [[Uiimageview alloc]init];
Self.advertImv.backgroundColor = [Uicolor Graycolor];
Self.advertimv.contentmode=uiviewcontentmodescaletofill; Self.advertImv.alpha = 0;//Setset to transparent [self ADDSUBVIEW:SELF.ADVERTIMV];
Add Gesture UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (click)];
tap.numberoftapsrequired=1;
[Self.advertimv Addgesturerecognizer:tap];
Set app icon Self.appimv =[[Uiimageview Alloc]init];
Self.appImv.image = [UIImage imagenamed:@ "iphone6p"];
[Self ADDSUBVIEW:SELF.APPIMV];
Set the name of the app self.appname = [[Uilabel alloc]init];
Self.appName.text = @ "Le school";
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 =@ "Make college life more exciting";
[Self addSubview:self.appPinyin]; Set AD size Uideviceresolution Ios_model = [Uidevicehardware currentresolution]; Get Device Size 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);
//Set the size of the app name Self.appName.frame =cgrectmake (0, 0, APPIMAGEVIEWW, 30);
Self.appname.center=cgpointmake (KSCREENW/2, appnameorigincentery);
Set the size of the app Pinyin Self.appPinyin.frame =cgrectmake (0, 0, Screen_width, 20);
Self.apppinyin.center=cgpointmake (KSCREENW/2, APPNAMEORIGINCENTERY+APPIMAGEVIEWH/2);
Set AD Size//self.advertimv.image = adimg;
Self.advertimv.frame= cgrectmake (0, 0, kscreenw,kscreenh);
return self;
/** * to the proxy class processing Picture Click button/-(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. -(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;
Iv. Summary
The above is the full content of iOS to achieve dynamic Open screen ads, I hope to learn or develop iOS can help, if you have questions you can message exchange.