iOS动画入门一

 一 动画介绍

在iOS中动画实现技术主要是:Core Animation。 Core Animation负责所有的滚动、旋转、缩小和放大以及所有的iOS动画效果。其中UIKit类通常都有animated:参数部分,它可以允许是否使用动画。 

本文将介绍UIView动画的实现方式,有基础方法和block方法。

二 实现方法

1 基础动画

 [UIView  beginAnimations:nil context:nil];  //动画开始
    //Code...
 [UIView commitAnimations];                  //动画结束

    //eg 设置lb向下移动
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:3];
    CGPoint point = self.lb.center;
    point.y += 100;
    self.lb.center = point;
    [UIView commitAnimations];

2 blcok方法1

 [UIView animateWithDuration:3   //动画持续时间
                     animations:^{
        //Code...
    }];

//eg 改变lb的透明度
    [UIView animateWithDuration:3 animations:^{
        self.lb.alpha = 0.5;
    }];

3 blcok方法2

UIView animateWithDuration:3   //动画持续时间
                     animations:^{
        //动画执行
    } completion:^(BOOL finished) {
        //动画完成后执行
    }];

//eg 旋转lb第一种方法:
    CGAffineTransform endAngel = CGAffineTransformMakeRotation(90.0f*(M_PI/180.0f));
    
    [UIView animateWithDuration:3 animations:^{
        self.lb.transform = endAngel;
    } completion:^(BOOL finished) {
        self.stateLb.text = @"动画完成了";
    }];


4 blcok方法3

[UIView animateWithDuration:3   //动画持续时间
                          delay:1   //动画延迟时间
                        options:UIViewAnimationOptionCurveEaseIn    //设置动画过渡效果
                     animations:^{
        //动画执行
    } completion:^(BOOL finished) {
        //动画完成后执行
    }];

 //eg 改变lb的字体大小 和位置
    [UIView animateWithDuration:3
                          delay:1
                        options:UIViewAnimationOptionCurveEaseInOut //设置动画过渡效果
                     animations:^{
        CGPoint center = self.lb.center;
        center.x = 200;
        self.lb.center = center;
        
        self.lb.textColor = [UIColor blueColor];
    } completion:^(BOOL finished) {
        self.stateLb.text = @"改变lb的字体大小 和位置 完成*";
    }];



5 blcok方法4

[UIView animateWithDuration:3       //动画持续时间
                          delay:1       //动画延迟时间
         usingSpringWithDamping:1.0     //设置类似弹簧效果
          initialSpringVelocity:5.0     //设置初始速度
                        options:UIViewAnimationOptionCurveLinear //设置动画过渡效果
                     animations:^{
    
    } completion:^(BOOL finished) {
        
    }];

[UIView animateWithDuration:3 delay:1 usingSpringWithDamping:1.0 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        CGPoint center = self.btn.center;
        center.y += 50;
        self.btn.center = center;
    } completion:^(BOOL finished) {
        self.stateLb.text = @"弹簧效果结束";
    }];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值