2009-12-14 76 views
0

這是這個問題的延續的代碼.... Allow horizontal scrolling only in the core-plot barchart?保持Y​​軸固定在位?

-(BOOL)pointingDeviceDraggedAtPoint:(CGPoint)interactionPoint 
{ 
    if (!self.allowsUserInteraction || !self.graph.plotArea) { 
     return NO; 
    } 
    CGPoint pointInPlotArea = [self.graph.plotArea convertPoint:interactionPoint toLayer:self.graph.plotArea]; 

    if (isDragging) { 

     pointInPlotArea.y = lastDragPoint.y;//-- Madhup Changed it for allwoing scrolling only in horizontal direction --// 




     //-- Madhup Changed it for allwoing scrolling only in horizontal direction --// 

     //CGPoint displacement = CGPointMake(pointInPlotArea.x-lastDragPoint.x, pointInPlotArea.y-lastDragPoint.y); 
     CGPoint displacement = CGPointMake(pointInPlotArea.x-lastDragPoint.x, 0); 
      //--******************************--// 
     CGPoint pointToUse = pointInPlotArea; 

     // Allow delegate to override 
     if ([self.delegate respondsToSelector:@selector(plotSpace:willDisplaceBy:)]) { 
      displacement = [self.delegate plotSpace:self willDisplaceBy:displacement]; 
      pointToUse = CGPointMake(lastDragPoint.x+displacement.x, lastDragPoint.y+displacement.y); 
     } 

     NSDecimal lastPoint[2], newPoint[2]; 
     [self plotPoint:lastPoint forPlotAreaViewPoint:lastDragPoint]; 
     [self plotPoint:newPoint forPlotAreaViewPoint:pointToUse]; 

     CPPlotRange *newRangeX = [[self.xRange copy] autorelease]; 
     CPPlotRange *newRangeY = [[self.yRange copy] autorelease]; 
     NSDecimal shiftX = CPDecimalSubtract(lastPoint[0], newPoint[0]); 
     NSDecimal shiftY = CPDecimalSubtract(lastPoint[1], newPoint[1]); 
     newRangeX.location = CPDecimalAdd(newRangeX.location, shiftX); 
     newRangeY.location = CPDecimalAdd(newRangeY.location, shiftY); 

     // Delegate override 
     if ([self.delegate respondsToSelector:@selector(plotSpace:willChangePlotRangeTo:forCoordinate:)]) { 
      newRangeX = [self.delegate plotSpace:self willChangePlotRangeTo:newRangeX forCoordinate:CPCoordinateX]; 
      newRangeY = [self.delegate plotSpace:self willChangePlotRangeTo:newRangeY forCoordinate:CPCoordinateY]; 
     } 

     self.xRange = newRangeX; 
     self.yRange = newRangeY; 

     //-- Madhup Changed it for keeping y axis fixed --// 
     NSLog(@"%@",self.graph.axisSet.axes); 

     NSMutableArray *axisArr= [[NSMutableArray alloc] initWithArray:self.graph.axisSet.axes]; 
     CPXYAxis *yAxis = [axisArr objectAtIndex:1]; 
     CGPoint point = yAxis.position; 
     point.y -= lastDragPoint.x; 
     yAxis.position = point; 
     [axisArr replaceObjectAtIndex:1 withObject:yAxis]; 
     self.graph.axisSet.axes = axisArr; 
     [axisArr release]; 

     NSLog(@"%@",self.graph.axisSet.axes); 
      //--******************************--// 

     lastDragPoint = pointInPlotArea; 



     return YES; 
    } 

    return NO; 
} 

現在從你的代碼的人可以看到,我能停止地圖只在水平方向上的滾動,但我仍然我無法保持y軸的固定。我在這個方法中也寫了一些代碼,但它似乎沒有工作。

+0

也許只是設置'interactionPoint.y = 0.f;'這個方法最開始將工作? – Pascal 2009-12-14 10:39:46

+0

你好,我試過你的代碼,但有plotArea和isDragging屬性的問題,似乎他們不能像這樣訪問了。你有什麼要改變的提示嗎?謝謝 – Luc 2010-07-29 21:50:34

回答

4

,如果你要修復軸滾動時添加此行

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)_graph.axisSet; 

axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0]; 
axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];