两朵飘动的小云

来源:互联网 发布:手机电子书阅读器软件 编辑:程序博客网 时间:2024/05/01 00:07

代码记录:


@interface ViewController (){

    UIImageView * v1;

    UIImageView * v2;

}


@end


@implementation ViewController



- (void)viewDidLoad {

    [superviewDidLoad];

    //[self CloudAinimate];

    [selfbgAnimate];

    // Do any additional setup after loading the view, typically from a nib.

}



-(void)bgAnimate {

    if (v1==nil) {

        v1 = [[UIImageViewalloc] initWithImage:[UIImageimageNamed: @"cloud"]];

        v2 = [[UIImageViewalloc] initWithImage:[UIImageimageNamed: @"cloud2"]];

        v1.alpha =v2.alpha =0;

        

        v1.frame =CGRectMake(20, -275,1024, 520);

        v2.frame =CGRectMake(120, -290,1024, 520);

        

        

        [self.viewaddSubview:v1];

        [self.viewaddSubview:v2];

    }

    

    NSLog(@"bganimate");

    float t =32.0f;

    [UIViewanimateWithDuration:4.0fdelay:0options:UIViewAnimationOptionCurveLinearanimations:^{

        //淡入出现

        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){

        [UIViewanimateWithDuration:t delay:0options:UIViewAnimationOptionCurveLinearanimations:^{

            //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);

            [UIViewanimateWithDuration:t delay:0options:UIViewAnimationOptionCurveLinearanimations:^{

                //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);

                [UIViewanimateWithDuration:t delay:0options:UIViewAnimationOptionCurveLinearanimations:^{

                    //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){

                    

                    [UIViewanimateWithDuration:t delay:0options:UIViewAnimationOptionCurveLinearanimations:^{

                        //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 = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"cloud.png"]];

        v2 = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"cloud2.png"]];

        v1.alpha =v2.alpha =0;

        

        v1.frame =CGRectMake(0,0, 500,300);

        v2.frame =CGRectMake(0,0, 500,400);

        

        

        [self.viewaddSubview:v1];

        [self.viewaddSubview:v2];

        

        [UIViewanimateWithDuration:4.0fdelay:0options:UIViewAnimationOptionCurveLinearanimations:^{

            

            v1.alpha =1;

            v2.alpha =1;

        } completion:^(BOOL finished){

            

            

        }];

        

        

    }

    

    v1.alpha =1;

    v2.alpha =1;

    

    NSLog(@"CloudAinimate");

    [UIViewanimateWithDuration:40.0fdelay:0options:UIViewAnimationOptionCurveLinearanimations:^{

        //淡入出现

        

        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 {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end



0 0
原创粉丝点击