我有一個應用程序,我使用CorePlot繪製圖形。我已經使用捏手勢實現了圖形本身的縮放,但我仍然無法使軸附近的標籤(包含像1,2等數字)的標籤正確縮放,因此不是1,主要間隔更改爲5或0.5(或任何其他數字)取決於捏手勢。CorePlot中的縮放軸
-(void) viewDidAppear
{
UIPinchGestureRecognizer* rec = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scalePiece:)];
// set options for this recognizer.
[self.view addGestureRecognizer:rec];
...
xMajorInterval = 1;
yMajorInterval = 1;
axisSet = (CPXYAxisSet *)graph.axisSet;
axisSet.xAxis.majorIntervalLength = CPDecimalFromFloat(xMajorInterval);
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.minorTickLength = 4.0f;
axisSet.xAxis.majorTickLength = 8.0f;
axisSet.xAxis.labelOffset = 1.0f;
axisSet.yAxis.majorIntervalLength = CPDecimalFromFloat(yMajorInterval);
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.minorTickLength = 4.0f;
axisSet.yAxis.majorTickLength = 8.0f;
axisSet.yAxis.labelOffset = 1.0f;
...
}
- (void)scalePiece:(UIPinchGestureRecognizer *)gestureRecognizer {
//Here I tried to change xMajorInterval and yMajorInterval and redraw axes
}
以下是我放大情節
- (void)scalePiece:(UIPinchGestureRecognizer *)gestureRecognizer {
if (PlotSpaceX > -0.1) {
if ([gestureRecognizer scale] > 1) {
PlotSpaceY = PlotSpaceY - 0.1;
PlotSpaceX = PlotSpaceX - 0.1;
}
}
if (PlotSpaceY >= -0.1) {
if ([gestureRecognizer scale] < 1){
PlotSpaceY = PlotSpaceY + 0.1;
PlotSpaceX = PlotSpaceX + 0.1;
}
}
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:plotSpace.xRange.location length:CPDecimalFromFloat(PlotSpaceX * 2.0)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:plotSpace.yRange.location length:CPDecimalFromFloat(PlotSpaceY * 2.0)];
majorInterval = majorInterval*PlotSpaceX/4;
intMajorInterval = majorInterval;
NSLog(@"%i", intMajorInterval);
axisSet.xAxis.majorIntervalLength = CPDecimalFromInt(intMajorInterval);
axisSet.yAxis.majorIntervalLength = CPDecimalFromInt(intMajorInterval);
}
在scalePiece方法我試圖改變xMajorInterval和yMajorInterval和重繪軸,但是,不幸的是,這種方法經常捏放操作的過程中調用標籤只顯示huuuge數字。
你能幫助我嗎?
你是如何計算mainIntervalLength的新值的? – 2011-02-19 01:41:29
這是我的問題 - 我應該如何更改xMajorInterval和yMajorInterval的值,以便標籤顯示正常的用戶友好數字 – Knodel 2011-02-19 10:04:21