微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Mac OSX 10.15.6 UpdateLayer描边行上的c#不在NScustomview中显示

如何解决Mac OSX 10.15.6 UpdateLayer描边行上的c#不在NScustomview中显示

我是C#中特定于OSX的MAC编程的新手; 我希望能够刷新customview以动态绘制线(即股票图表) 在鼠标按下动作上使用ViewController.cs中的数组,我根本不在那儿。

首先,我试图弄清楚为什么使用UpdateLayer()方法根本不显示任何内容 而我试图划一条线。如果我只在一次drawrect中使用同一笔画线,那么我只能传递一次这种单词,而不能从ViewController.cs中传递任何参数, 我还试图弄清楚如何刷新customview,因此drawrect只调用一次。虽然我想刷新视图,但是我需要使用UpdateLayer()来代替,但是UpdateLayer没有任何显示,因此笔画无法正常工作。

我一直在网上搜索C#可可中的清晰示例, 我能找到的大多数示例都使用其他语言,例如Swift,他们在鼠标单击时使用setneedsdisplay刷新自定义视图,但我找不到C#的等效语言。

using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using AppKit;
using CoreGraphics;

namespace Mac13_UpdLayer
{
    public partial class CustView : AppKit.NSView
    {
        #region Constructors

        // Called when created from unmanaged code
        public CustView(IntPtr handle) : base(handle)
        {
            Initialize();
        }

        // Called when created directly from a XIB file
        [Export("initWithCoder:")]
        public CustView(NSCoder coder) : base(coder)
        {
            Initialize();

        }

        // Shared initialization code
        void Initialize()
        {
            this.WantsLayer = true;
            this.LayerContentsRedrawPolicy = NSViewLayerContentsRedrawPolicy.OnSetNeedsdisplay;

        }

        public override void DrawRect(CGRect dirtyRect)
        {

               base.DrawRect(dirtyRect);

        }

        public override bool WantsUpdateLayer
        {
            get
            {
                return true;
            }
        }
        
        public override void UpdateLayer()
        {


            base.UpdateLayer();
            NSColor.LabelColor.Set();
            NSColor.magenta.Set();
            NSBezierPath path = new NSBezierPath();
            path.linewidth = 3;
            CGPoint c001 = new CGPoint(0,0);
            CGPoint c003 = new CGPoint(this.AccessibilityFrame.Width,this.AccessibilityFrame.Height);
            path.Moveto(c001);
            path.Lineto(c003);
            path.stroke();


        }
        #endregion
    }
}

using System;

using AppKit;
using Foundation;

namespace Mac13_UpdLayer
{
    public partial class ViewController : NSViewController
    {
        public ViewController(IntPtr handle) : base(handle)
        {
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Do any additional setup after loading the view.


       

            //   this.View.Layer.BackgroundColor = NSColor.DarkGray.CGColor;
        }

        public override NSObject Representedobject
        {
            get
            {
                return base.Representedobject;
            }
            set
            {
                base.Representedobject = value;
                // Update the view,if already loaded.
   
            }
        }

        partial void ButRefAction(Foundation.NSObject sender)
        {
            //declare array
            //refresh customview from array
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。