willChangePlotRangeTo:对Core Plot中的图没有影响 [英] willChangePlotRangeTo: makes no difference to graphs in Core Plot
问题描述
我在我的应用中运行了以下代码,以防止在触摸或捏合手势期间缩放y轴。我已经分配了axisConstraints,也已经分配了globalXRange和Y。
i have the below code running in my app to stop the y-axis from being zoomed and scaled during touch or pinch gestures. I have axisConstraints assigned already, as are the globalXRange and Y.
-(CGPoint)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CGPoint)displacement{
return CGPointMake(displacement.x,0);
}
-(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
willChangePlotRangeTo:(CPTPlotRange *)newRange
forCoordinate:(CPTCoordinate)coordinate{
if (coordinate == CPTCoordinateY)
{
newRange = ((CPTXYPlotSpace*)space).yRange;
}
NSLog(@"Plot changes %@", newRange);
return newRange;
}
我的问题是从日志中记录了4-5个地块变化首次运行应用程序时页面首次显示时的日志?该代码似乎正常工作,只是我没有得到任何图,而且Y上也没有标签和刻度。
My issue is that from the logs, 4-5 plot changes are recorded in the log while the page is first displaying when first running the app?? The code seems to work correctly, just i get no plots, plus no label + ticks on the Y.
2013-11-10 17:30:52.259 MyApp[8953:a0b] Pinch changes <<CPTPlotRange: 0x8d96680> {0, 30158.4}>
2013-11-10 17:30:52.260 MyApp[8953:a0b] Pinch changes <<CPTPlotRange: 0x8d94e70> {0, 40}>
2013-11-10 17:30:52.260 MyApp[8953:a0b] Pinch changes <<CPTPlotRange: 0x8d94330> {0, 34.44}>
2013-11-10 17:30:52.268 MyApp[8953:a0b] Pinch changes <<CPTPlotRange: 0x8da6da0> {0, 30158}>
2013-11-10 17:30:52.268 MyApp[8953:a0b] Pinch changes <<CPTPlotRange: 0x8da80e0> {0, 9}>
编辑:
我做了些混帐随即插入NSLOG,下面的代码创建了一个手势:
I did some mucking around with inserting NSLOG and the below code is what is creating the a gesture:
CPTXYPlotSpace *plotSpace2 = (CPTXYPlotSpace *) graph2.defaultPlotSpace;
plotSpace2.allowsUserInteraction = YES;
plotSpace2.delegate = self;
plotSpace2.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromInteger([difference integerValue]*1.03)];
plotSpace2.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(9)];
plotSpace2.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromInteger([difference integerValue]*1.03)];
plotSpace2.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(9)];
所以有plotspace.delegate = self是原因,更改为x.delegate = self并解决了
so having plotspace.delegate=self was the cause, changed to x.delegate=self and that fixes the gesture issue i was seeing.
不幸的是,我只缩放x的代码没有任何区别。 :-/
Unfortunately the code i have for zooming only the x makes no difference. :-/
推荐答案
您的代理人禁止对 yRange
进行任何更改。在设置初始 yRange
之后,设置绘图空间委托。
Your delegate is preventing any changes to the yRange
. Set the plot space delegate after you set up the initial yRange
.
plotSpace2.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)
length:CPTDecimalFromFloat(9)];
plotSpace2.delegate = self;
此行为在1.4版中已更改。在以前的版本中,仅在缩放时才调用 -plotSpace:willChangePlotRangeTo:forCoordinate:
。现在,只要绘图范围发生变化,就可以调用它。
This behavior changed in release 1.4. In prior releases, -plotSpace:willChangePlotRangeTo:forCoordinate:
was only called when pinch-scaling. Now, it is called any time the plot range changes.
这篇关于willChangePlotRangeTo:对Core Plot中的图没有影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!