从自定义渲染器调用共享代码类以更新触摸Xamarin的移动时会抛出此异常:
Application.DisplayAlerts = True
此处生成错误的代码:
iOS渲染器:
UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
共享班级
[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;
});
}
}
}
我正在尝试让共享代码类知道触摸移动到的位置。值得注意的是CustomTabbedPageRenderer类还有两个UISwipeGestureRecognizer。