iOS開發- 啟動動畫(動態歡迎介面,非靜態Default)

來源:互聯網
上載者:User

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

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

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




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

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

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


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


1.AppDelegate.h中聲明一個UIImageView

@property (strong, nonatomic) UIImageView *splashView;

2.AppDelegate.m實現相關功能

@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];                     }     ];}


學習的路上,與君共勉。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.