【发布时间】:2013-04-30 14:25:28
【问题描述】:
如果按下绘图符号,我想使用scatterPlot:plotSymbolWasSelectedAtRecordIndex: 方法在我的图表中设置一个带有标签出口的自定义uiview。
但是如何给绘图区域提供 UIView 或者如何覆盖 CPTLayer 来绘制我的自定义 UIView?
谢谢
【问题讨论】:
如果按下绘图符号,我想使用scatterPlot:plotSymbolWasSelectedAtRecordIndex: 方法在我的图表中设置一个带有标签出口的自定义uiview。
但是如何给绘图区域提供 UIView 或者如何覆盖 CPTLayer 来绘制我的自定义 UIView?
谢谢
【问题讨论】:
CPTLayer 是CALayer 的子类,因此您不能只使用自定义UIView 作为Core Plot 注释。但是,您可以将自定义视图作为 Core Plot 托管视图的同级插入(不是子视图!)。使用绘图空间获取绘图区域中被触摸数据点的坐标,并使用内置的CALayer方法将坐标从绘图区域层转换为图形层。
【讨论】:
CGPoint viewPoint = [plot plotAreaPointOfVisiblePointAtIndex:index];MyCustomView *view = [MyCustomView alloc] initWithFrame:CGRectMake(viewPoint.x,viewPoint.y,100,100);[self.graph.hostingView addSubview:view];