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

本人ios初學者,為自己學習方便,復制各位大神的學習性文章放在自己簡書里,僅作為自己學習方便使用,如果作者疑此行為侵權,請隨時聯系本人刪除,如有共同學習者復制此文章,請注明原出處

最近在使用《青蔥日記》這款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實現相關功能

@synthesizesplashView;

- (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];

returnYES;

}

-(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];

}

];

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 1、設置UILabel行間距 NSMutableAttributedString* attrString = [[...
    FF_911閱讀 1,424評論 0 3
  • 1、設置UILabel行間距 NSMutableAttributedString* attrString = [[...
    十年一品溫如言1008閱讀 1,720評論 0 3
  • //設置尺寸為屏幕尺寸的時候self.window = [[UIWindow alloc] initWithFra...
    LuckTime閱讀 838評論 0 0
  • 轉自:http://www.code4app.com/blog-866962-1317.html1、設置UILab...
    MMOTE閱讀 1,686評論 1 1
  • 所謂感覺,沒有那么難理解,身材外貌是表,性格內涵是里,一言一行體現素養,穿衣打扮彰顯風格,沒有對與錯的人,只有合不...
    綠野V仙蹤閱讀 235評論 0 0