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
?
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.
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) => {
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With