Question

Je simple UIButton avec une propriété Alpha que je voudrais animer de 1.0f à 0.0f, puis revenir à 1.0f. Ceci est essentiellement répond à Touchdown.

Aussi, est-il quelque chose de spécial que je dois faire si la routine, je fais appel de n'est pas sur le thread principal (délégué async a invoqué le ThreadPool)?

Dois-je utiliser CAAnimation?

Merci!

Était-ce utile?

La solution

A moins que les tuyaux de quelqu'un avec une manière mono de le faire, je dis utilisation:

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

}

Autres conseils

Merci pour le code iPhone message.

La deuxième réponse utilise une variable globale et ignore les paramètres de la fonction de rappel. Voici ce que je me suis dit aujourd'hui basée sur la première réponse.

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

Ceci est assez simple:

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();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top