在CPTXYGraph饼图上获得触摸反馈

时间:2012-07-06 05:54:50

标签: ios core-plot

我正在使用Core Plot中的CPTXYGraph绘制饼图。我使用了委托方法

-(void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index

在单击饼图的特定切片时执行某些操作。但是当我触摸饼图时,我需要显示反馈或某种类型的图像更改,以表示触摸特定切片就像按钮事件一样。

是否有任何委托方法可以实现相同的目标。

2 个答案:

答案 0 :(得分:2)

还有一些工作要做。

首先,将其实现为饼图委托功能。

-(void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index
{
    indexOfPieGraphPlot = index; //gives index of pie which is selected.
    isPieGraphPlot = YES;     //boolean. if set to yes, will call rootcontroller function which will add pop up.
}

然后在.h文件中添加 CPTPlotSpaceDelegate

然后使用此功能

- (BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceUpEvent:(id)event atPoint:(CGPoint)point
{
    if(isPieGraphPlot) //if yes call showpopup of rootcontroller
    {
    isPieGraphPlot = NO;
    [rootController showPopUpView:point indexForPlot:indexOfPieGraphPlot];
    // point gives the x,y of the pie over which you want a pop up.
    }
    else    // if no then call remove popup from rootcontroller. this, incase user clicks anywhere else in graph.
    {
        [rootController removePopUp];
    }
    return  YES;
}

答案 1 :(得分:0)

在数据源中实现-sliceFillForPieChart:recordIndex:方法。跟踪选定的切片(如果有)并使用它来确定要应用于每个切片的填充。每当选择改变时,在图上调用-reloadData以强制它加载新的切片填充。

相关问题