iOS 动画(1)

设置UIImageView

_imageAime = [[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 100, 100)];

_imageAime.image =[UIImage imageNamed:@"icon_baiban"];

[self.view addSubview:_imageAime];

//缩放效果

-(void)Zoom{

  [UIView animateWithDuration:3 animations:^{
        //动画的逻辑
    _imageAime.frame =CGRectMake(10, 200, 300, 250);
    } completion:^(BOOL finished) {
        //动画结束之后要执行的代码
        //重开了一个UIView动画,还原位置
        [UIView animateWithDuration:3 animations:^{
            _imageAime.frame =CGRectMake(50, 100, 100, 100);
        }];
    }];

}

//旋转效果

-(void)rotation{

    CABasicAnimation *basianimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];

     //设置时长

    [basianimation setDuration:10];

    //重复次数

    [basianimation setRepeatCount:2];

   //所改变属性的起始值

    basianimation.fromValue = [NSNumber numberWithDouble:2];

    //所改变属性的结束时的值

    basianimation.toValue = [NSNumber numberWithDouble:M_PI * 20];
    [_imageAime.layer addAnimation:basianimation forKey:nil];

    //动画结束时是否执行逆动画

    basianimation.autoreverses = YES;

}

//虚化效果

-(void)grammaticalization{

  //第三种UIView动画的另一种写法(没有block)
    [UIView beginAnimations:@"view动画的另一种写法" context:nil];
    //设置时长
    [UIView setAnimationDuration:1];
    //设置重复次数
    [UIView setAnimationRepeatCount:NSIntegerMax];
    //动画的逻辑
    _imageAime.alpha =0.4;
    //结束动画
    [UIView commitAnimations];

}

//

-(void)tremble{

 //2,延时时间(等待)3,颤抖效果,值越小,抖动的越厉害 4,开始时的动画速度,值越大速度越快
    [UIView animateWithDuration:2 delay:1 usingSpringWithDamping:0.2 initialSpringVelocity:3 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        _imageAime.frame =CGRectMake(100, 400, 300, 250);
    } completion:^(BOOL finished) {
        
    }];

}

-(void)curve{

    //关键帧动画
    CAKeyframeAnimation *keyanimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    //创建一个路径, 用来记录每一帧
    CGMutablePathRef path = CGPathCreateMutable();
    //指定移动的起点
    CGPathMoveToPoint(path, NULL, _imageAime.center.x, _imageAime.center.y);
    //画一条曲线(贝塞尔曲线)
    CGPathAddCurveToPoint(path, NULL, 100, 100, 370, 320, 100, 690);
    
    //设置路径
    [keyanimation setPath:path];
    //设置时间
    [keyanimation setDuration:3];
    //设置重复次数
    [keyanimation setRepeatCount:1];
    
    [_imageAime.layer addAnimation:keyanimation forKey:@"keyanimation"
     ];

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值