我如何用单触摸为Uibutton Alpha属性进行动画动画
-
16-09-2019 - |
题
我有一个简单的Uibutton,其中有一个Alpha属性,我想从1.0F到0.0F,然后返回1.0F。这基本上是对触地得分的响应。
另外,如果我在主线程上不呼叫的例程(异步代表在ThreadPool上调用),我需要做什么特别的事情?
我应该使用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();
}
不隶属于 StackOverflow