JKX*_*JKX 2 animation objective-c uibutton ios
我有一个按钮,我想为背景颜色设置动画,就好像它从底部到顶部填充一样。
现在我只是用动画改变颜色
IE
[UIView animateWithDuration:2.0 animations:^{
button.layer.backgroundColor = [UIColor redColor].CGColor;
} completion:NULL];
Run Code Online (Sandbox Code Playgroud)
这工作得很好,但我希望动画从底部向上填充,就像填充液体一样。
编辑:不确定它是否有区别,但按钮是圆形的
尝试这个。这里 btn 是按钮的出口,v 是我们将添加到按钮中用于动画目的的视图。
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];
}];
Run Code Online (Sandbox Code Playgroud)