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 ?

4

2 回答 2

8

那是一个的绑定错误(错误类型),出于兼容性原因,Animate仍然使用NSAction完成处理程序。

为了解决这个问题AnimateNotify,MonoTouch 中添加了一种新方法。这个版本接受一个UICompletionHandler这样定义的:

public delegate void UICompletionHandler (bool finished);

因此,您的问题的解决方案是使用较新的AnimateNotifyAPI。

于 2012-09-04T16:05:35.140 回答
5

所以应该看起来像:

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

}, delegate (bool finished) {

});

或者使用 lambda 语法:

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

}, (finished) => {

});
于 2013-01-29T07:43:09.803 回答