我想做这样的事情:http://youtu.be/PeRhxSCx2xM
我尝试实现这个方法:
//viewDidLoad
//plotSpace.delegate = self;
- (CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
willChangePlotRangeTo:(CPTPlotRange *)newRange
forCoordinate:(CPTCoordinate)coordinate {
NSLog(@"WillChangePlotRangeTo");
// only allows scrolling to the right
// remove this to have scrolling in both directions
if (newRange.locationDouble < 0.0F) {
newRange.location = CPTDecimalFromFloat(0.0);
}
// Adjust axis to keep them in view at the left and bottom;
// adjust scale-labels to match the scroll.
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
if (coordinate == CPTCoordinateX) {
axisSet.yAxis.orthogonalCoordinateDecimal = newRange.location;
axisSet.xAxis.titleLocation = CPTDecimalFromFloat(newRange.locationDouble +
(newRange.lengthDouble / 2.0F));
} else {
axisSet.xAxis.orthogonalCoordinateDecimal = newRange.location;
axisSet.yAxis.titleLocation = CPTDecimalFromFloat(newRange.locationDouble +
(newRange.lengthDouble / 2.0F));
}
return newRange;
}
我试试这个,这个解决方案在我缩小时有效,但在放大时不起作用。
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(1.0) length:CPTDecimalFromFloat(3.0)];
plotSpace.globalYRange = plotSpace.yRange;
任何人都请解释我,正确的结果是什么,以及它的实际工作方式。
感谢回复
答案 0 :(得分:12)
最简单的方法是忽略newRange
并返回y坐标的现有yRange
。您也不需要在这里更新轴属性。有更简单的方法可以做到这一点。
// leave the titleLocation for both axes at the default (NAN) to center the titles
xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
- (CPTPlotRange *)plotSpace:(CPTPlotSpace *)space
willChangePlotRangeTo:(CPTPlotRange *)newRange
forCoordinate:(CPTCoordinate)coordinate {
CPTPlotRange *updatedRange = nil;
switch ( coordinate ) {
case CPTCoordinateX:
if (newRange.locationDouble < 0.0F) {
CPTMutablePlotRange *mutableRange = [[newRange mutableCopy] autorelease];
mutableRange.location = CPTDecimalFromFloat(0.0);
updatedRange = mutableRange;
}
else {
updatedRange = newRange;
}
break;
case CPTCoordinateY:
updatedRange = ((CPTXYPlotSpace *)space).yRange;
break;
}
return updatedRange;
}
答案 1 :(得分:1)
我有类似的情况和问题,它让我抓狂,因为我忘了设置代表:
plotSpace.delegate = self;