Frage

Ich habe ein einfaches Uibutton mit einer Alpha -Immobilie, die ich von 1,0F auf 0,0 ° F animieren möchte, und dann zurück zu 1,0f. Dies reagiert im Grunde auf Touchdown.

Gibt es auch etwas Besonderes, das ich tun muss, wenn die Routine, von der ich rufe, nicht im Haupt -Thread ist (Async -Delegierter auf dem Threadpool aufgerufen)?

Soll ich Caanimation verwenden?

Vielen Dank!

War es hilfreich?

Lösung

Wenn jemand nicht mit einer Mono -Art zu tun ist, sage ich: Verwenden Sie:

- (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];

}

Andere Tipps

Vielen Dank für den iPhone -Code -Beitrag.

Die zweite Antwort besteht darin, eine globale Variable zu verwenden und die Parameter für den Rückruf zu überspringen. Hier ist, was ich heute auf der Grundlage der ersten Antwort herausgefunden habe.

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();
}

Das ist ziemlich einfach:

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();
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top