IOS Animation动画基础

本文详细介绍如何使用Objective-C在iOS中创建动画效果,包括传统动画和Block动画两种方式,并通过实例展示了如何设置动画属性如延迟时间、持续时间及动画结束后的回调处理。


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

 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值