UIButton闪烁的动画 [英] UIButton flashing animation
问题描述
我想知道是否可以将闪烁的动画应用于UIButton。我已经搜索过,但只找到了用于脉冲动画的代码,该代码会不断更改UIButton的大小。相反,我在考虑某种闪烁的动画,以提醒用户他必须按下按钮。我能想到的唯一方法就是通过不断更改alpha来使用:
I was wondering if it was possible to apply a flashing animation to a UIButton. I have searched but only found the code for a pulse animation which changes the size of my UIButton continuously. I instead was thinking about some kind of flashing animation to alert the user he has to press the button. The only approach to the problem I can think of is by changing the alpha constantly using:
[self setAlpha:0.5];
...但它不会像闪烁的按钮一样可见。
...but it won't be as visible as a flashing button.
推荐答案
也许不是最好的方法,并且实际上并不允许您停止闪烁……但这很简单,有效,并且不能阻碍用户互动:
Perhaps not the best way, and doesn't really allow you to stop the flashing... but this is simple, works, and does not hinder user interaction:
- (void)viewDidLoad
{
[self flashOn:myButton];
}
- (void)flashOff:(UIView *)v
{
[UIView animateWithDuration:.05 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^ {
v.alpha = .01; //don't animate alpha to 0, otherwise you won't be able to interact with it
} completion:^(BOOL finished) {
[self flashOn:v];
}];
}
- (void)flashOn:(UIView *)v
{
[UIView animateWithDuration:.05 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^ {
v.alpha = 1;
} completion:^(BOOL finished) {
[self flashOff:v];
}];
}
这篇关于UIButton闪烁的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!