如何使用 MonoTouch 为 UIButton Alpha 属性设置动画 [英] How can I animate a UIButton Alpha property with MonoTouch
本文介绍了如何使用 MonoTouch 为 UIButton Alpha 属性设置动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有 Alpha 属性的简单 UIButton,我想将它从 1.0f 动画到 0.0f,然后再回到 1.0f.这基本上是响应 TouchDown.
I have a simple UIButton with an Alpha property that I would like to animate from 1.0f to 0.0f, and then back to 1.0f. This is basically responding to TouchDown.
另外,如果我调用的例程不在主线程上(在 ThreadPool 上调用异步委托),我需要做什么特别的事情吗?
Also, is there anything special I need to do if the routine I am calling from is not on the main thread (async delegate invoked on the ThreadPool)?
我应该使用 CAAnimation 吗?
Should I use CAAnimation?
谢谢!
推荐答案
除非有人用单一的方式来做这件事,否则我说使用:
Unless someone pipes up with a mono way to do it, I say use:
- (void) pulseButton {
button.alpha = 0.0;
[UIView beginAnimations:nil context:button]; {
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(makeVisibleAgain:finished:context:)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:0.50];
button.alpha = 0.0;
} [UIView commitAnimations];
}
- (void)makeVisibleAgain:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
UIButton *button = ((UIButton *) context);
[UIView beginAnimations:nil context:nil]; {
[UIView setAnimationDelegate:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.5];
button.alpha = 1.0;
} [UIView commitAnimations];
}
这篇关于如何使用 MonoTouch 为 UIButton Alpha 属性设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文