- 效果圖
12.gif
ed.gif
原理
先創(chuàng)建一個(gè)UIViewController并且將根視圖控制器給它,再將圖片按順序加入控制器的視圖中臂容,并把圖片視圖的透明度設(shè)置為0沮峡,還要把所有視圖依次加入一個(gè)圖片數(shù)組中荔睹,然后設(shè)置一個(gè)定時(shí)器镐依,按順序把圖片的透明度調(diào)為1甩挫,當(dāng)最后一個(gè)圖片顯示時(shí),結(jié)束定時(shí)器炮障,并把根視圖交給主界面代碼
#import "LauchViewController.h"
#import "Common.h"
#import "MainTabBarController.h"
@interface LauchViewController ()
{
NSMutableArray *imageViews;//圖片數(shù)組
int count;//計(jì)數(shù)count
}
@end
@implementation LauchViewController
- (void)viewDidLoad {
[super viewDidLoad];
count = 0;
self.view.backgroundColor = [UIColor orangeColor];
[self _createBackImageView];
[self _createImageViews];
//2 定時(shí)器的調(diào)用
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(startAnimation:) userInfo:nil repeats:YES];
}
//創(chuàng)建背景圖片
-(void)_createBackImageView{
UIImageView *backImageV = [[UIImageView alloc]initWithFrame:self.view.bounds];
backImageV.image = [UIImage imageNamed:@"Default"];
[self.view addSubview:backImageV];
}
//定時(shí)器調(diào)用的方法
-(void)startAnimation:(NSTimer*)timer{
if (count == imageViews.count) {
//定時(shí)器停止
[timer invalidate];
//顯示主界面
UIStoryboard *storyB = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
MainTabBarController *maintabBarC =[storyB instantiateInitialViewController];
self.view.window.rootViewController = maintabBarC;
}else{
[UIView animateWithDuration:0.1 animations:^{
UIImageView *imageV = imageViews[count];
imageV.alpha = 1;
}];
}
count++;
}
//創(chuàng)建圖片視圖
-(void)_createImageViews{
//創(chuàng)建圖片數(shù)組
imageViews = [NSMutableArray array];
CGFloat width = KScreenWidth/4;
CGFloat height= KScreenHeight/6;
CGFloat x = 0;
CGFloat y = 0;
//循環(huán)創(chuàng)建24張圖片視圖
for (int i = 0; i<24; i++) {
NSString *imageName = [NSString stringWithFormat:@"%d.png",i+1];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
imageView.alpha = 0;
imageView.frame =CGRectMake(0, 0, width, height);
if (i<4) {//前四張
x = i*width;
y = 0;
}else if (i<8){//最右邊的四張
x =3*width;
y =height*(i-3);
}else if (i<12){//最下面的四張
//x =KScreenWidth-width*1;
x =KScreenWidth-width*(i-7);
y = KScreenHeight-height;
}else if (i<16){//最左邊的四張
x = 0;
y = KScreenHeight-height*(i-10);
}else if (i<18){//上邊2個(gè)
x = width*(i-15);
y =height;
}else if (i<20){//右邊2個(gè)
x = width*2;
y = height*(i-16);
}else if (i<22){//下面2個(gè)
x = KScreenWidth-width*(i-18);
y = KScreenHeight-height*2;
}else if (i<24){//最后2個(gè)
x = width;
y = KScreenHeight-height*(i-19);
}
imageView.origin = CGPointMake(x, y);
//按照順序?qū)D片放在圖片數(shù)組中
[imageViews addObject:imageView];
[self.view addSubview:imageView];
}
}