I have this static Source Analysis warning in Xamarin Studio:
API Usage Issue: Use the *Notify method that has a
UICompletion Handler completion
parameter, thebool
will tell you if the operation finished
when invoking UIView.Animate(double duration, Action animation, Action completion)
:
UIView.Animate(duration,
() => Animation(),
() => Completion());
However, I can't seem to be able to pass parameters to the lambda expression. None of these options compile:
(bool) => Completion()
(finished) => Completion()
(bool finished) => Completion()
How can I pass this finished
parameter to to completion block?
The Animate
static methods use NSAction
methods, more of a C# style annotation and AnimateNotify
use UICompletionHandler
methods, ObjC-style...
The Animate
methods are just helper wrappers around AnimateNotify
:
So instead of:
UIView.Animate(30, () => { }, () => { });
You can use:
UIView.AnimateNotify(30, () => { }, (bool finished) => { });
The result is the same....
Ref: https://github.com/xamarin/xamarin-macios/blob/fc55e4306f79491fd269ca2495c6a859799cb1c6/src/UIKit/UIView.cs#L121
Looks like you might be able to use one of the AnimateNotify
or AnimateNotifyAsync
method overloads as that passes back UICompletionHandler
with a bool
:
UIView.AnimateNotify(10, () => { }, finished => { });
OR
await UIView.AnimateNotifyAsync(10, () => { }, 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