ios - Xamarin iOS UIView 没有 DrawLayer 覆盖

标签 ios xamarin

我目前正在将 XCode/Swift 中的 iOS 应用程序翻译成 Xamarin iOS.

在现有的swift代码中,有一个自定义控件继承自UIView,并覆盖了drawLayer函数。

但是,当我尝试在 XamarinUIView 自定义控件中覆盖同一成员时,没有覆盖。

谁能帮我弄清楚我做错了什么。

谢谢

最佳答案

此方法不存在直接使用,您必须使用 CALayer 类本身。

例如

public class BlueView : UIView
{
    [Export ("layerClass")]
    public static Class GetLayerClass ()
    {
        return new Class (typeof (BlueLayer));
    }

    public override void Draw (RectangleF rect)
    {
        // Do nothing, the Layer will do all the drawing
    }
}

public class BlueLayer : CALayer
{
    public override void DrawInContext (CGContext ctx)
    {
        ctx.SetFillColor (0, 0, 1, 1);
        ctx.FillRect (Bounds);
    }
}

引用:

CALayer Details

CALayer With UIView

关于ios - Xamarin iOS UIView 没有 DrawLayer 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36197322/

相关文章:

ios - UILabel 调整字体以适合文本

javascript - 在 HTML5 视频元素中播放电影时如何在 IOS 上显示非全尺寸视频?

ios - 当 TouchMoved 函数上的 x 坐标发生变化时,动态更改 UICollection View 的宽度

c# - Xamarin PCL 中缺少 Type.GetProperties()

ios - Xamarin 表单 - IOS : How to detect the UIView size changed

c# - xamarin 中带有 NSUrlSessionDelegate 的客户端证书

ios - 由于编译器优化而无法本地化 String?

ios - timeIntervalSince1970 转换在 Swift 3 中返回错误的年份

c# xamarin Error inflating 类 ActionMenuView

android - 在 Xamarin 上使用来自 Android Studio 的 xml