Iphone – How to animate a UIButton Alpha property with MonoTouch

iphoneuikitxamarin.ios

I have a simple UIButton with an Alpha property that I would like to animate from 1.0f to 0.0f, and then back to 1.0f. This is basically responding to TouchDown.

Also, is there anything special I need to do if the routine I am calling from is not on the main thread (async delegate invoked on the ThreadPool)?

Should I use CAAnimation?

Thanks!

Best Answer

Unless someone pipes up with a mono way to do it, I say use:

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

}