c# - 无法覆盖 UIView.Draw 方法

标签 c# ios uiview xamarin draw

我需要覆盖 draw 方法,但我收到错误消息:

Draw(System.Drawing.PointF)' is marked as an override but no suitable method found to override (CS0115).

这就是我所做的:我创建一个新项目,添加一个空类并尝试覆盖。

代码如下:

using System;
using UIKit;
using System.Drawing;
using CoreGraphics;
using CoreImage;
using Foundation;
using CoreAnimation;

namespace Test
{
    public class Tester : UIView
    {
        CGPath path;

        public override void Draw (PointF rect){
            base.Draw ();
        }


        public Tester ()
        {
            path = new CGPath ();
        }

    }
}

实际上,我正在尝试 Xamarin 的教程。 http://developer.xamarin.com/guides/ios/application_fundamentals/graphics_animation_walkthrough/

最佳答案

问题是您使用统一 API 创建程序(请参阅顶部的“使用 CoreImage”)。在统一 API 中,我们不再使用 PointF、SizeF 或 RectangleF,因为它们是 32 位结构,因此它们不适用于 32/64 位模式。

在 Unified 中,您需要使用“CGRect”而不是“RectangleF”

所以要修复你的程序,你所要做的就是用“CGRect”替换“RectangleF”

教程目前反射(reflect)的是 Classic API,一旦我们正式发布 Unified 的最终版本,它们就会切换过来。

关于c# - 无法覆盖 UIView.Draw 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27315978/

相关文章:

ios - 添加 UICollectionViewController 作为子 UIView 崩溃

c# - 在 1 个网站上使用和注册多个 ASP.NET mvc3 解决方案

iphone - 带分页的水平 UIScrollView

ios - NSFetchedResultsController:删除 1 行使应用程序崩溃

ios - 归档时 : A struct gives "Redundant protocol error", 而不是运行时

iOS:UIButton 不显示

c# - 如何在 ASP.Net MVC 的 RedirectToAction 中传递临时数据

c# - 合并列表并只返回重复项

c# - 读取图像文件元数据

objective-c - UIView动画VS核心动画