Reputation: 241
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;
}
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}>
EDIT:
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)];
so having plotspace.delegate=self was the cause, changed to x.delegate=self and that fixes the gesture issue i was seeing.
Unfortunately the code i have for zooming only the x makes no difference. :-/
Upvotes: 2
Views: 731
Reputation: 27381
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;
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.
Upvotes: 2