首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >核心情节中的可点击传奇

核心情节中的可点击传奇
EN

Stack Overflow用户
提问于 2016-10-11 12:57:56
回答 2查看 149关注 0票数 0

我使用核心绘图文件来创建我的图表。但是CorePlot不包含事件“点击图例项目”。

如何检测用户对图例项的单击?

代码语言:javascript
复制
class ViewController: NSViewController, CPTPlotDataSource, CPTPieChartDataSource {

@IBOutlet weak var graphView: CPTGraphHostingView!

override func viewDidLoad() {
    super.viewDidLoad()

    let graph = CPTXYGraph(frame: CGRect.zero)        
    var axes = graph.axisSet as! CPTXYAxisSet
    var lineStyle = CPTMutableLineStyle()
    lineStyle.lineWidth = 0
    axes.xAxis?.axisLineStyle = lineStyle
    axes.yAxis?.axisLineStyle = lineStyle


    var pie = CPTPieChart()
    pie.pieRadius = 100
    pie.dataSource = self
    pie.centerAnchor = CGPoint(x: 0.18, y: 0.75)
    graph.add(pie)        

    var theLegend=CPTLegend(graph: graph)
    var legendFill=CPTFill(color: CPTColor.gray())
    theLegend.fill = legendFill
    var legendLineStyle = CPTMutableLineStyle()
    legendLineStyle.lineColor = CPTColor.white()
    theLegend.borderLineStyle = legendLineStyle
    theLegend.cornerRadius = 2.0
    theLegend.frame = CGRect(x: 0, y: 0, width: 0.1, height: 50)
    theLegend.numberOfColumns = 1

    graph.legend = theLegend
    graph.legendDisplacement = CGPoint(x: 0.5, y: 300)

    self.graphView.hostedGraph = graph
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-10-12 00:39:13

核心情节传说可以有一个委托,它在鼠标向下、鼠标向上和/或被选中(鼠标向下,在同一项上鼠标向上)事件上调用。有关可用方法的详细信息,请参阅CPTLegendDelegate协议。除非您需要一些委托不包括的特定行为,否则您不需要担心响应者链。

票数 2
EN

Stack Overflow用户

发布于 2016-10-11 13:17:09

如果您深入研究核心图的源代码,您可以遵循CPTLegend的继承链,一直到CPTLayer:

https://github.com/core-plot/core-plot/blob/master/framework/Source/CPTLegend.h https://github.com/core-plot/core-plot/blob/master/framework/Source/CPTBorderedLayer.h https://github.com/core-plot/core-plot/blob/master/framework/Source/CPTAnnotationHostLayer.h https://github.com/core-plot/core-plot/blob/master/framework/Source/CPTLayer.h

如果您检查CPTLayer的头文件,它符合CPTResponder,如果您转到CPTResponder的源代码:

https://github.com/core-plot/core-plot/blob/master/framework/Source/CPTResponder.h

您将注意到,除其他方法外,还有两种相关方法:

-(BOOL)pointingDeviceDownEvent:(非空CPTNativeEvent *)事件atPoint:(CGPoint)interactionPoint;

-(BOOL)pointingDeviceUpEvent:(非空CPTNativeEvent *)事件atPoint:(CGPoint)interactionPoint;

我认为您可能可以做的是将CPTLegend子类化,并根据检测单击的需要覆盖一个或两个方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39977800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档