从下至上对UIButton背景颜色进行动画处理,目标C [英] Animate UIButton Background color from bottom up, Objective C

查看:103
本文介绍了从下至上对UIButton背景颜色进行动画处理,目标C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,希望对背景颜色进行动画处理,好像它是从底部填充到顶部一样。

I have a button which I would like to animate the background color as if it is filling from the bottom to the top.

现在我只是在更改动画的颜色

Right now I'm just changing the color with animation

ie

[UIView animateWithDuration:2.0 animations:^{
    button.layer.backgroundColor = [UIColor redColor].CGColor;
} completion:NULL];

效果很好,但我希望动画从下往上填充

This works just fine but I'd love the animation to fill from the bottom up like it is filling up with liquid.

编辑:不确定是否有区别,但按钮是圆形的

not sure if it makes a difference but the button is round

推荐答案

尝试一下。这里的btn是按钮的出口,而v是我们将添加到按钮以进行动画处理的视图。

Try this. Here btn is the outlet to your button and v is the view we will be adding to your button for animation purpose.

UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, [self btn].frame.size.height,
                                                     [self btn].frame.size.width, [self btn].frame.size.height)];
[v setBackgroundColor:[UIColor purpleColor]];
v.userInteractionEnabled = NO;
v.exclusiveTouch = NO;
[[self btn] addSubview:v];

[UIView animateWithDuration:0.45 animations:^{

    CGRect currentRect = v.frame;
    currentRect.origin.y = 0;
    [v setAlpha:1];
    [v setFrame:currentRect];
    [[self btn] sendSubviewToBack:v];
}];

这篇关于从下至上对UIButton背景颜色进行动画处理,目标C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆