Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将参数传递给NSAction?_C#_Ios_Xamarin.ios_Uikit_Uiviewanimation - Fatal编程技术网

C# 如何将参数传递给NSAction?

C# 如何将参数传递给NSAction?,c#,ios,xamarin.ios,uikit,uiviewanimation,C#,Ios,Xamarin.ios,Uikit,Uiviewanimation,每个人都知道在ObjC中我们有 + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion 请注意,completion块有一个BOOL参数。 现

每个人都知道在ObjC中我们有

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
请注意,
completion
块有一个BOOL参数。 现在让我们看看Monotouch:

public static void Animate (double duration, double delay, UIViewAnimationOptions options, NSAction animation, NSAction completion)
行动是:

public delegate void NSAction ();
只有委托,没有任何参数。此外,在单触式“内部”中,我们可以看到:

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 ();
        }
    });
}
注意
委托(boolx)
,它调用函数就像我需要的那样。现在,我如何将
动作
作为完成传递给
UIView.Animate

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

为了解决这个问题,MonoTouch添加了一个新方法
AnimateNotify
。此版本接受一个
UICompletionHandler
,其定义如下:

public delegate void UICompletionHandler (bool finished);

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

这样看起来应该是:

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

}, delegate (bool finished) {

});
或使用lambda语法:

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

}, (finished) => {

});

你不觉得是时候把旧包装去掉了吗?@Maxim:我想一夜之间把它去掉会有点过头。但对我来说,废除它听起来是个好主意。(我不是机器翻译开发人员,只是一个用户。)