我的 Xamarin 项目有一个广告 SDK 绑定(bind)。绑定(bind)在这里:https://github.com/bbhsu2/XamarinAdMarvelBinding
我的问题来自方法:
[Export("adMarvelViewFrame")]
RectangleF AdMarvelViewFrame();
在我的类里面,我是这样实现的:
[Export("adMarvelViewFrame")]
public RectangleF AdMarvelViewFrame()
{
return new RectangleF(0.0f, 0.0f, UIScreen.MainScreen.Bounds.Width, 250.0f);
}
但是,当加载 View 时,出现错误:
UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
我(认为)我理解这个错误的含义,但是当 native 代码在其他地方调用它时,我如何在主线程上调用它?
最佳答案
您正在调用的 UIKIt 方法是 UIScreen.MainScreen。
简单的解决方法是在类变量中预取 UIScreen.MainScreen,然后在您的 AdMarvelViewFrame 中使用该类变量。
关于c# - 从 Xamarin 绑定(bind)调用 UIKit 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26902207/