iOS啓動動畫

最近在使用《青蔥日記》這款App,發現它的啓動界面做的很精美。

不同我自己之前簡單的替換Default.png圖片。 它的動態效果做的不錯。

於是乎,花了點時間,自己實現了這個功能。 其實也很簡單,具體效果如下


\


實現起來也不困難。因爲我們知道,在應用啓動的時候,它會先執行AppDelegate.m中的

?
1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

執行完之後,纔會進入視圖。如果,我們在這個方法中加入一些動畫,那麼就會在動畫執行完之後再進入我們的rootview。這就是實現原理。 很簡單吧。


下面直接給出實現這一效果的源碼,很簡單。不多說廢話(當然,實現方法很多。 我只是給出我自己的方法)


1.AppDelegate.h中聲明一個UIImageView

@property (strong, nonatomic) UIImageView *splashView;

2.AppDelegate.m實現相關功能

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
@synthesize splashView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];
     
    splashView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
    [splashView setImage:[UIImage imageNamed:@"back_"]];
     
    [self.window addSubview:splashView];
    [self.window bringSubviewToFront:splashView];
     
     
    [self performSelector:@selector(scale_1) withObject:nil afterDelay:0.0f];
    [self performSelector:@selector(scale_2) withObject:nil afterDelay:0.5f];
    [self performSelector:@selector(scale_3) withObject:nil afterDelay:1.0f];
    [self performSelector:@selector(scale_4) withObject:nil afterDelay:1.5f];
    [self performSelector:@selector(scale_5) withObject:nil afterDelay:2.0f];
    [self performSelector:@selector(showWord) withObject:nil afterDelay:2.5f];
 
     
    return YES;
}
 
-(void)scale_1
{
    UIImageView *round_1 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 240, 15, 15)];
    round_1.image = [UIImage imageNamed:@"round_"];
    [splashView addSubview:round_1];
    [self setAnimation:round_1];
}
 
-(void)scale_2
{
    UIImageView *round_2 = [[UIImageView alloc]initWithFrame:CGRectMake(105, 210, 20, 20)];
    round_2.image = [UIImage imageNamed:@"round_"];
    [splashView addSubview:round_2];
    [self setAnimation:round_2];
}
 
-(void)scale_3
{
    UIImageView *round_3 = [[UIImageView alloc]initWithFrame:CGRectMake(125, 170, 30, 30)];
    round_3.image = [UIImage imageNamed:@"round_"];
    [splashView addSubview:round_3];
    [self setAnimation:round_3];
}
 
-(void)scale_4
{
    UIImageView *round_4 = [[UIImageView alloc]initWithFrame:CGRectMake(160, 135, 40, 40)];
    round_4.image = [UIImage imageNamed:@"round_"];
    [splashView addSubview:round_4];
    [self setAnimation:round_4];
}
 
-(void)scale_5
{
    UIImageView *heart_1 = [[UIImageView alloc]initWithFrame:CGRectMake(130, 180, 100, 100)];
    heart_1.image = [UIImage imageNamed:@"heart_"];
    [splashView addSubview:heart_1];
    [self setAnimation:heart_1];
}
 
-(void)setAnimation:(UIImageView *)nowView
{
     
    [UIView animateWithDuration:0.6f delay:0.0f options:UIViewAnimationOptionCurveLinear
                     animations:^
                    {
                        // 執行的動畫code
                        [nowView setFrame:CGRectMake(nowView.frame.origin.x- nowView.frame.size.width*0.1, nowView.frame.origin.y-nowView.frame.size.height*0.1, nowView.frame.size.width*1.2, nowView.frame.size.height*1.2)];
                     }
                     completion:^(BOOL finished)
                    {
                         // 完成後執行code
                        [nowView removeFromSuperview];
                     }
     ];
     
 
}
 
-(void)showWord
{
     
    UIImageView *word_ = [[UIImageView alloc]initWithFrame:CGRectMake(75, 440, 170, 29)];
    word_.image = [UIImage imageNamed:@"word_"];
    [splashView addSubview:word_];
     
    word_.alpha = 0.0;
    [UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionCurveLinear
                     animations:^
                     {
                         word_.alpha = 1.0;
                     }
                     completion:^(BOOL finished)
                     {
                         // 完成後執行code
                         [NSThread sleepForTimeInterval:1.0f];
                         [splashView removeFromSuperview];
                     }
     ];
}
發佈了2 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章