美文网首页iOS基本功
UIViewAnimationWithBlocks

UIViewAnimationWithBlocks

作者: Z了个Y | 来源:发表于2016-12-29 10:27 被阅读32次

本文主要介绍下UIView基于block形式的基本动画

一、基本动画

[UIView animateWithDuration:0.25 // 动画的持续时间  
                      delay:0 // 动画执行的延迟时间 
                    options:0 // 执行的动画选项, 
                 animations:^{ // 要执行的动画代码 } 
                 completion:^(BOOL finished) { // 动画执行完毕后的调用}
];

缩略版

[UIView animateWithDuration:0.25 // 动画的持续时间  
                 animations:^{ // 要执行的动画代码 } 
                 completion:^(BOOL finished) { // 动画执行完毕后的调用}
];

精简版

[UIView animateWithDuration:0.25 // 动画的持续时间  
                 animations:^{ // 要执行的动画代码 } 
];

带弹簧效果

//弹簧效果
- (void)animationWithSpring
{
    /**
     * Damping:阻尼系数 值越小弹簧效果越明显 取值0到1
     * Velocity:初始的速度,数值越大一开始移动越快
     */
    [UIView animateWithDuration:0.25 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:20 options:0 animations:^{
        _redView.zy_centerY += 150;
    } completion:nil];
}

二、关键帧动画

让一个view绕矩形运动

//关键帧动画
- (void)keyFrameAnimation
{
    /**
     *  RelativeStartTime:相对于Duration(4秒)所开始的时间(第0秒开始动画)
     *  relativeDuration:相对于Duration(4秒)所持续的时间
     */
    [UIView animateKeyframesWithDuration:4 delay:0 options:0 animations:^{
        [UIView addKeyframeWithRelativeStartTime:0.0                   relativeDuration:1/4.0 animations:^{
            //第0秒开始动画 持续1秒
            _redView.zy_centerX += 100;
        }];
        [UIView addKeyframeWithRelativeStartTime:1/4.0 relativeDuration:1/4.0 animations:^{
            //第1秒开始动画 持续1秒
            _redView.zy_centerY += 100;
        }];
        [UIView addKeyframeWithRelativeStartTime:2/4.0 relativeDuration:1/4.0 animations:^{
            //第2秒开始动画 持续1秒
            _redView.zy_centerX -= 100;
        }];
        [UIView addKeyframeWithRelativeStartTime:3/4.0 relativeDuration:1/4.0 animations:^{
            //第3秒开始动画 持续1秒
            _redView.zy_centerY -= 100;
        }];
    } completion:nil];
}

三、转场动画

- (void)transitionAnimation
{
    [UIView transitionWithView:_redView duration:1.0 options:UIViewAnimationOptionTransitionCurlUp animations:^{
        _redView.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1];
    } completion:nil];
}

相关文章

  • UIViewAnimationWithBlocks

    本文主要介绍下UIView基于block形式的基本动画 一、基本动画 缩略版 精简版 带弹簧效果 二、关键帧动画 ...

  • UIView 动画总结

    UIViewAnimation 这是最基本的动画 UIViewAnimationWithBlocks 对基本UIV...

  • bounce回弹效果

    对于拥有动态呈现效果的view来说,使用UIView(UIViewAnimationWithBlocks)的ani...

  • iOS transitionFromView 翻转View

    用了UIView分类UIViewAnimationWithBlocks里的类方法: 需要注意的是fromView和...

网友评论

    本文标题:UIViewAnimationWithBlocks

    本文链接:https://www.haomeiwen.com/subject/vxtjmttx.html