我有,我想从1.0F动画为0.0f,然后回到1.0F的alpha属性的简单的UIButton。 这基本上是响应触地得分。
此外,有没有什么特别的,我需要做的,如果我从调用例程不是在主线程(异步转委关于线程池调用)?
我应该使用CAAnimation?
谢谢!
我有,我想从1.0F动画为0.0f,然后回到1.0F的alpha属性的简单的UIButton。 这基本上是响应触地得分。
此外,有没有什么特别的,我需要做的,如果我从调用例程不是在主线程(异步转委关于线程池调用)?
我应该使用CAAnimation?
谢谢!
除非有人管了一个单声道的方式来做到这一点,我说的使用:
- (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];
}
谢谢你的iPhone后置代号。
第二个答案是使用全局变量,并跳过回调的参数。 这是我今天想通了基于第一个答案。
private void BeginPulse (Button button)
{
UIView.BeginAnimations (button+"fadeIn", button.Handle);
UIView.SetAnimationDelegate (this);
UIView.SetAnimationDidStopSelector (new MonoTouch.ObjCRuntime.Selector ("makeVisibleAgain:finished:context:"));
UIView.SetAnimationCurve(UIViewAnimationCurve.EaseOut);
UIView.SetAnimationDuration (0.5);
button.Alpha = 0.25f;
UIView.CommitAnimations ();
}
[Export ("makeVisibleAgain:finished:context:")]
private void EndPulse (NSString animationId, NSNumber finished, UIButton button)
{
UIView.BeginAnimations (null, System.IntPtr.Zero);
UIView.SetAnimationDelegate (this);
UIView.SetAnimationCurve (UIViewAnimationCurve.EaseIn);
UIView.SetAnimationDuration (0.5);
button.Alpha = 1;
UIView.CommitAnimations();
}
这是非常简单的:
UIView button;
public void fadeButtonInAndOut()
{
UIView.BeginAnimations("fadeOut");
UIView.SetAnimationDelegate(this);
UIView.SetAnimationDidStopSelector(new Selector("fadeOutDidFinish"));
UIView.SetAnimationDuration(0.5f);
button.Alpha = 0.0f;
UIView.CommitAnimations();
}
[Export("fadeOutDidFinish")]
public void FadeOutDidFinish()
{
UIView.BeginAnimations("fadeIn");
UIView.SetAnimationDuration(0.5f);
button.Alpha = 1.0f;
UIView.CommitAnimations();
}