C# 更改Xamarin表单中的TranslationX属性会导致UIKit一致性异常

C# 更改Xamarin表单中的TranslationX属性会导致UIKit一致性异常,c#,ios,xamarin,xamarin.ios,xamarin.forms,C#,Ios,Xamarin,Xamarin.ios,Xamarin.forms,从自定义渲染器调用共享代码类以更新触摸的移动时,Xamarin引发以下异常: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread. 下面是生成错误的代码: iOS渲染器: [assembly: ExportRenderer (typeof (CustomTabbedPage), typeof (CustomTabbedPageRenderer))]

从自定义渲染器调用共享代码类以更新触摸的移动时,Xamarin引发以下异常:

UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
下面是生成错误的代码:

iOS渲染器:

[assembly: ExportRenderer (typeof (CustomTabbedPage), typeof (CustomTabbedPageRenderer))]

namespace CustomRenderer.iOS
{
    public class CustomTabbedPageRenderer : PageRenderer
    {
        ...
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            ...

            ((CustomTabbedPage)this.Element).updateDragDelta( (double) ( _touchMovedToPoint.X - _touchStartingPoint.X ));

        }

     }

}
共享类

namespace CompanyName
{   
    public class CustomTabbedPage : BaseContentPage
    {
            ...

            public void updateDragDelta(double x)
             {
                 Device.BeginInvokeOnMainThread (() => {
                     dragDeltaX = x;
                     this.TranslationX = _lockPosition + dragDeltaX;
                  });
             }
    }
}
和堆栈跟踪:

  at UIKit.UIApplication.EnsureUIThread () [0x00023] in /Users/builder/data/lanes/1926/6916d0e3/source/maccore/src/UIKit/UIApplication.cs:71 
  at UIKit.UIViewController.ViewDidLayoutSubviews () [0x00000] in /Users/builder/data/lanes/1926/6916d0e3/source/maccore/src/build/ios/native/UIKit/UIViewController.g.cs:1005 
  at Xamarin.Forms.Platform.iOS.PlatformRenderer.ViewDidLayoutSubviews () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
  at CoreAnimation.CATransaction.Commit () [0x00000] in /Users/builder/data/lanes/1926/6916d0e3/source/maccore/src/build/ios/native/CoreAnimation/CATransaction.g.cs:78 
  at Xamarin.Forms.Platform.iOS.CADisplayLinkTicker.StartThread () [0x0002e] in <filename unknown>:0 
  at System.Threading.Thread.StartInternal () [0x00016] in /Users/builder/data/lanes/1926/6916d0e3/source/mono/mcs/class/corlib/System.Threading/Thread.cs:696 
位于/Users/builder/data/lanes/1926/6916d0e3/source/maccore/src/UIKit/UIApplication.cs中的UIKit.UIApplication.EnsureUIThread()[0x00023]
在/Users/builder/data/lanes/1926/6916d0e3/source/maccore/src/build/ios/native/UIKit/UIViewController.g.cs中的UIKit.UIViewController.viewdlayoutsubviews()[0x00000]处
位于:0中的Xamarin.Forms.Platform.iOS.PlatformRenderer.viewdilayoutsubview()[0x00000]
在(包装器管理为本机)objc运行时。消息传递:void_objc_msgSend(intptr,intptr)
在/Users/builder/data/lanes/1926/6916d0e3/source/maccore/src/build/ios/native/corenanimation/CATransaction.g.cs:78中的corenanimation.CATransaction.Commit()[0x00000]
位于:0中的Xamarin.Forms.Platform.iOS.CADisplayLinkTicker.StartThread()[0x0002e]
在/Users/builder/data/lanes/1926/6916d0e3/source/mono/mcs/class/corlib/System.Threading/Thread.cs:696中的System.Threading.Thread.StartInternal()[0x00016]
我试图让共享代码类知道touch移动到了哪里。还值得注意的是,CustomTabbedPageRenderer类还有两个UISweepGestureRecognitor