IOS Animation动画基础

来源:互联网 发布:安卓手机java编程软件 编辑:程序博客网 时间:2024/04/29 11:43


-(void)createTredition

{

    //1.创建动画

    UIView*animationView=[[UIView alloc]initWithFrame:CGRectMake(100100100100)];

    animationView.tag=100;

    animationView.backgroundColor=[UIColor orangeColor];

    [self.view addSubview:animationView];

    //两个参数 1 是动画的标示 2 个式动画携带的内容

    [UIView beginAnimations:@"123" context:(__bridge void *)(animationView)];

    //设置动画延迟时间

    [UIView setAnimationDelay:2];

    //设置代理监控动画何时开始和结束

    [UIView setAnimationDelegate:self];

    //动画开始方法

    [UIView setAnimationWillStartSelector:@selector(animationDidStart:context:)];

    //动画结束

    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

    

    

    //2 动画持续时间

    [UIView setAnimationDuration:2];

    //3 动画的动作 修该坐标信息 改变颜色 改变变量 改变透明度

    animationView.frame=self.view.bounds;

    animationView.backgroundColor=[UIColor greenColor];

    animationView.alpha=0.4;

    animationView.transform=CGAffineTransformMakeRotationM_PI_4);

    //4动画的提交

    [UIView commitAnimations];

    

}

//2 block 动画的方式

-(void)creatBlockAnimation

{

    UIView*animationView=[[UIView alloc]initWithFrame:CGRectMake(100100100100)];

    animationView.tag=100;

    animationView.backgroundColor=[UIColor orangeColor];

    [self.view addSubview:animationView];

    [UIView animateWithDuration:3 animations:^{

        animationView.frame=self.view.bounds;

    }];

    [UIView animateWithDuration:3 animations:^{

        animationView.backgroundColor=[UIColor yellowColor];

        //animationView.frame=self.view.bounds;

    } completion:^(BOOL finished) {

        //动画完成要走的地方

        [UIView animateWithDuration:3 animations:^{

                  animationView.frame=self.view.bounds;

              }];

    }];

   // delay延迟时间

    [UIView animateWithDuration:5 delay:2 options:UIViewAnimationOptionLayoutSubviews animations:^{

        animationView.transform=CGAffineTransformMakeRotation(M_PI_4);

        animationView.backgroundColor=[UIColor greenColor];

    } completion:^(BOOL finished) {

        [UIView animateWithDuration:3 animations:^{

               animationView.frame=self.view.bounds;

            animationView.backgroundColor=[UIColor brownColor];

         }];

 

    }];

}

 

//动画结束执行的方法必须包含 动画标示 携带的内容 和是否动画完成 三个参数

 

 

 

//动画执行的方法 必须携带动画标示和内容两个参数

- (void)animationDidStart:(NSString *)animationID context:(void *)context

{

    NSLog(@"animationID=%@,countext=%@",animationID,context);

}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context

{

    BOOL ret=finished.boolValue;

    NSLog(@"nimationID=%@ context=%@ finish=%d",animationID,context,ret);

 

}

1 3
原创粉丝点击