您的位置:首页 > 移动开发

iOS-OC-APP开场动画

2016-01-25 14:37 337 查看
//
//  AppDelegate.m
//  开场动画demo
//
//  Created by ZFJ_APPLE on 16/1/25.
//  Copyright © 2016年张福杰. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@property (strong,nonatomic) UIImageView *splashView;//开场动画的背景图片

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

//这是开场动画函数
[selfsetStartAnimation];

return YES;
}

#pragma mark - 设置启动动画
- (void)setStartAnimation
{
[self.windowmakeKeyAndVisible];

_splashView = [[UIImageViewalloc]initWithFrame:self.window.bounds];
[_splashViewsetImage:[UIImageimageNamed:@"4.png"]];

[self.windowaddSubview:_splashView];
[self.windowbringSubviewToFront:_splashView];

//设置动画
[selfperformSelector:@selector(scale_1)withObject:nilafterDelay:0.0f];
[selfperformSelector:@selector(scale_2)withObject:nilafterDelay:0.5f];
[selfperformSelector:@selector(scale_3)withObject:nilafterDelay:1.0f];
[selfperformSelector:@selector(scale_4)withObject:nilafterDelay:1.5f];
[selfperformSelector:@selector(scale_5)withObject:nilafterDelay:2.0f];
[selfperformSelector:@selector(showWord)withObject:nilafterDelay:2.5f];
}

- (void)scale_1
{
NSLog(@"1-%@",[NSThreadcurrentThread]);
UIImageView *round_1 = [[UIImageViewalloc]initWithFrame:CGRectMake(100,240, 15, 15)];
round_1.image = [UIImageimageNamed:@"3.jpg"];
[_splashView addSubview:round_1];
[self setAnimation:round_1];
}

- (void)scale_2
{
NSLog(@"2-%@",[NSThreadcurrentThread]);
UIImageView *round_2 = [[UIImageViewalloc]initWithFrame:CGRectMake(105,210, 20, 20)];
round_2.image = [UIImageimageNamed:@"3.jpg"];
[_splashView addSubview:round_2];
[self setAnimation:round_2];
}

- (void)scale_3
{
NSLog(@"3-%@",[NSThreadcurrentThread]);
UIImageView *round_3 = [[UIImageViewalloc]initWithFrame:CGRectMake(125,170, 30, 30)];
round_3.image = [UIImageimageNamed:@"3.jpg"];
[_splashView addSubview:round_3];
[self setAnimation:round_3];
}

- (void)scale_4
{
NSLog(@"4-%@",[NSThreadcurrentThread]);
UIImageView *round_4 = [[UIImageViewalloc]initWithFrame:CGRectMake(160,135, 40, 40)];
round_4.image = [UIImageimageNamed:@"3.jpg"];
[_splashView addSubview:round_4];
[self setAnimation:round_4];
}

- (void)scale_5
{
UIImageView *heart_1 = [[UIImageViewalloc]initWithFrame:CGRectMake(130,180, 100, 100)];
heart_1.image = [UIImageimageNamed:@"3.jpg"];
[_splashView addSubview:heart_1];
[self setAnimation:heart_1];
}

- (void)showWord
{

UIImageView *word_ = [[UIImageViewalloc]initWithFrame:CGRectMake(75,440, 170, 170)];
word_.image = [UIImageimageNamed:@"3.jpg"];
[_splashView addSubview:word_];

word_.alpha = 0.0;
[UIViewanimateWithDuration:1.0fdelay:0.0foptions:UIViewAnimationOptionCurveLinear
animations:^
{
word_.alpha = 1.0;
}
completion:^(BOOL finished)
{
// 完成后执行code
[NSThreadsleepForTimeInterval:1.0f];
[_splashViewremoveFromSuperview];
}
];
}

- (void)setAnimation:(UIImageView *)nowView
{

[UIViewanimateWithDuration:0.6fdelay:0.0foptions: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)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: