7

Well, everyone knows that in ObjC we have

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

Notice that completion block has a BOOL argument. Now let's look at Monotouch:

public static void Animate (double duration, double delay, UIViewAnimationOptions options, NSAction animation, NSAction completion)

NSAction is:

public delegate void NSAction ();

Just the delegate without any arguments. Moreover, in Monotouch "internals" we can see:

public static void Animate (double duration, double delay, UIViewAnimationOptions options, 
NSAction animation, NSAction completion)
{
    UIView.AnimateNotify (duration, delay, options, animation, delegate (bool x)
    {
        if (completion != null)
        {
            completion ();
        }
    });
}

Notice delegate (bool x), It calls the function just like I need. Now, how can I pass Action<bool> as completion to UIView.Animate ?

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
folex
  • 5,122
  • 1
  • 28
  • 48

2 Answers2

8

That was an old binding bug (wrong type) and, for compatibility reason, Animate still use a NSAction completion handler.

To fix this a new method AnimateNotify was added to MonoTouch. This version accept a UICompletionHandler which is defined like this:

public delegate void UICompletionHandler (bool finished);

So the solution to your problem is to use the newer AnimateNotify API.

poupou
  • 43,413
  • 6
  • 77
  • 174
5

So that should look like:

UIView.AnimateNotify(duration, 0, UIViewAnimationOptions.CurveEaseInOut, delegate () {

}, delegate (bool finished) {

});

Or with lambda syntax:

UIView.AnimateNotify(duration, 0, UIViewAnimationOptions.CurveEaseInOut, () => {

}, (finished) => {

});
superlogical
  • 14,332
  • 9
  • 66
  • 76