代码记录:
@interface ViewController (){
UIImageView * v1;
UIImageView * v2;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//[self CloudAinimate];
[self bgAnimate];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)bgAnimate {
if (v1==nil) {
v1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"cloud"]];
v2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"cloud2"]];
v1.alpha = v2.alpha = 0;
v1.frame = CGRectMake(20, -275, 1024, 520);
v2.frame = CGRectMake(120, -290, 1024, 520);
[self.view addSubview:v1];
[self.view addSubview:v2];
}
NSLog(@"bganimate");
float t = 32.0f;
[UIView animateWithDuration:4.0f delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
//淡入出现
v1.frame = CGRectMake(0, -280, 1024, 520);
v2.frame = CGRectMake(-512+128, -300, 1024, 520);
v1.transform = CGAffineTransformMakeScale(1.0, 1.0);
v2.transform = CGAffineTransformMakeScale(1.0, 1.0);
// v1.alpha = 0.2;
// v2.alpha = 0.2;
v1.alpha = 0.8;
v2.alpha = 0.8;
} completion:^(BOOL finished){
[UIView animateWithDuration:t delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
//v1向放大快速右移动, v2缩小慢速
v1.frame = CGRectMake(-512, -350, 1024, 520);
v2.frame = CGRectMake(-1204, -250, 1024, 520);
v1.transform = CGAffineTransformMakeScale(1.2, 1.2);
v2.transform = CGAffineTransformMakeScale(0.8, 0.8);
// v1.alpha = 0.2;
// v2.alpha = 0.2;
v1.alpha = 0.8;
v2.alpha = 0.8;
} completion:^(BOOL finished){
v2.frame = CGRectMake(1024, -250, 1024, 520);
[UIView animateWithDuration:t delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
//v1向淡出, v2慢速
v1.frame = CGRectMake(-1024, -300, 1024, 520);
v2.frame = CGRectMake(512-128, -350, 1024, 520);
v1.transform = CGAffineTransformMakeScale(1.4, 1.4);
v2.transform = CGAffineTransformMakeScale(1.0, 1.0);
//v1.alpha = 0.1;
// v2.alpha = 0.15;
v1.alpha = 0.5;
v2.alpha = 0.55;
} completion:^(BOOL finished){
v1.frame = CGRectMake(1024, -350, 1024, 520);
v1.transform = CGAffineTransformMakeScale(0.6, 0.6);
[UIView animateWithDuration:t delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
//v1向右侧进入, v2快速左侧移动
v1.frame = CGRectMake(512, -300, 1024, 520);
v2.frame = CGRectMake(0, -300, 1024, 520);
v1.transform = CGAffineTransformMakeScale(0.8, 0.8);
v2.transform = CGAffineTransformMakeScale(1.2, 1.2);
// v1.alpha = 0.15;
// v2.alpha = 0.1;
v1.alpha = 0.5;
v2.alpha = 0.55;
} completion:^(BOOL finished){
[UIView animateWithDuration:t delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
//v1向右侧进入, v2快速左侧移动
v1.frame = CGRectMake(20, -250, 1024, 520);
v2.frame = CGRectMake(-512+108, -350, 1024, 520);
v1.transform = CGAffineTransformMakeScale(0.9, 0.9);
v2.transform = CGAffineTransformMakeScale(1.1, 1.1);
// v1.alpha = 0.2;
//v2.alpha = 0.1;
v1.alpha = 0.8;
v2.alpha = 0.4;
} completion:^(BOOL finished){
// if (__userToken) return;
}];
}];
}];
}];
}];
}
-(void)CloudAinimate
{
if (v1==nil) {
v1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cloud.png"]];
v2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cloud2.png"]];
v1.alpha = v2.alpha = 0;
v1.frame = CGRectMake(0, 0, 500, 300);
v2.frame = CGRectMake(0, 0, 500, 400);
[self.view addSubview:v1];
[self.view addSubview:v2];
[UIView animateWithDuration:4.0f delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
v1.alpha = 1;
v2.alpha = 1;
} completion:^(BOOL finished){
}];
}
v1.alpha = 1;
v2.alpha = 1;
NSLog(@"CloudAinimate");
[UIView animateWithDuration:40.0f delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
//淡入出现
CGRect t = v1.frame;
if( t.origin.x == 0 )
{
v1.frame = CGRectMake(-1024, 300, 1024, 768);
v2.frame = CGRectMake(0, 300, 1024, 768);
}
else
{
v1.frame = CGRectMake(0, 300, 1024, 768);
v2.frame = CGRectMake(-1024, 300, 1024, 768);
}
}completion:^(BOOL finished)
{
CGRect t = v1.frame;
if(t.origin.x == -1024 )
{
v1.frame = CGRectMake(1024, 300, 1024, 768);
}
else
{
v2.frame = CGRectMake(1024, 300, 1024, 768);
}
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end