无法覆盖UIView.Draw方法

问题描述 投票:3回答:2

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

Draw(System.Drawing.PointF)'被标记为覆盖,但没有找到合适的方法来覆盖(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/

c# ios uiview xamarin draw
2个回答
4
投票

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

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

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

这些教程目前反映的是Classic API,一旦我们正式发布Unified的最终版本,它们将被切换。


1
投票

您不能覆盖不同的方法。原始方法没有参数。如果要覆盖Draw方法,则需要删除Draw函数参数。

© www.soinside.com 2019 - 2024. All rights reserved.