问题描述
我是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 (将#修改为@)