如何在coreplot / ios 8中放大或缩小代码?

时间:2014-12-12 07:59:14

标签: objective-c ios8 core-plot

我绘制了一个包含两个y轴和x轴的折线图。

现在我想为放大和缩放提供限制/限制。 我使用以下代码来限制

-(CPTPlotRange*)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate
{
    if([newRange locationDouble] < 0)
    {
        if(coordinate == CPTCoordinateX)
            return  [(CPTXYPlotSpace*)space xRange];
        else if(coordinate == CPTCoordinateY)
            return [(CPTXYPlotSpace*)space yRange];
    }
    if([newRange locationDouble] < 1000)
    {
        if(coordinate == CPTCoordinateX)
            return  [(CPTXYPlotSpace*)space xRange];
        else if(coordinate == CPTCoordinateY)
            return [(CPTXYPlotSpace*)space yRange];
    }

    return newRange;
}

and for zooming i used following code

-(BOOL)plotSpace:(CPTPlotSpace *)space shouldScaleBy:(CGFloat)interactionScale aboutPoint:(CGPoint)interactionPoint

{
    CPTGraph *graph = self.hostView.hostedGraph;

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;

   // plotSpace.delegate = self;


    NSInteger xAxisMin = 0;
    NSInteger xAxisMax = 15;

    NSInteger yAxisMin = 0;
    NSInteger yAxisMax = 100;



    if ((plotSpace.xRange>= [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xAxisMin) length:CPTDecimalFromDouble(2*(xAxisMax-xAxisMin))])||



        ((plotSpace.yRange>= [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yAxisMin) length:CPTDecimalFromDouble(2*(yAxisMax-yAxisMin))])))



    {



        //return NO;

        plotSpace.allowsUserInteraction = YES;

        CPTGraph *graph = self.hostView.hostedGraph;


        CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;

        plotSpace.delegate = self;

        plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xAxisMin) length:CPTDecimalFromFloat(xAxisMax - xAxisMin)];

        plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yAxisMin) length:CPTDecimalFromFloat(yAxisMax - yAxisMin)];

        plotSpace.allowsUserInteraction = YES;

        return YES;

    }

    else if ((plotSpace.xRange<= [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xAxisMin) length:CPTDecimalFromDouble((xAxisMax-xAxisMin)/2)])||



             ((plotSpace.yRange<= [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yAxisMin) length:CPTDecimalFromDouble((yAxisMax-yAxisMin)/2)])))

    {

        //[_hostingView setAllowPinchScaling:NO];

         plotSpace.allowsUserInteraction = YES;

        //return NO;


        CPTGraph *graph = self.hostView.hostedGraph;

        CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;

        plotSpace.delegate = self;

        plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xAxisMin) length:CPTDecimalFromFloat(xAxisMax - xAxisMin)];

        plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yAxisMin) length:CPTDecimalFromFloat(yAxisMax - yAxisMin)];

        plotSpace.allowsUserInteraction = YES;

       // [hostingView setAllowPinchScaling:YES];



        return YES;

    }

    return YES;      



}  

但问题是上面这个应该是ScaleBy:委托不调用。 我无法理解为什么不这样做。

请提供代码以缩放和缩小到某种程度。

1 个答案:

答案 0 :(得分:0)

-plotSpace:shouldScaleBy:aboutPoint:方法仅在响应托管视图上的捏合手势时调用。每次更改都会调用-plotSpace:willChangePlotRangeTo:forCoordinate:方法,因此您可以在那里进行所有限制检查。