どのように私はMonoTouchでとUIButton alphaプロパティをアニメーション化することができます

StackOverflow https://stackoverflow.com/questions/1470356

  •  16-09-2019
  •  | 
  •  

質問

私は戻っ1.0Fに、その後は0.0fに1.0Fからアニメーション化したい、と考えalphaプロパティを持つ単純なUIButtonを持っています。これは、基本的には、タッチダウンに応答されます。

また、私はから呼び出していますルーチンは、メインスレッド(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();
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top