核心情节放大 - pinchgesture

时间:2013-04-30 18:55:28

标签: core-plot pinch

我有缩放手势的缩放问题,主要问题是当我缩放时我会缩放视图中心,所以如果我捏住右上角或右下角,缩放就在视图中心。 这是我的代码,如何编辑它以便在捏合触摸中间进行缩放?

- (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer{

if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {

    scala = [gestureRecognizer scale];
    nextScala = [gestureRecognizer scale];

    //NSLog(@"Scala: %f Gesture Scala %f",scala,[gestureRecognizer scale]);
}
else if (gestureRecognizer.state == UIGestureRecognizerStateChanged) {


    //CGPoint pointUno = [gestureRecognizer locationOfTouch:0 inView:[gestureRecognizer view]];
    //CGPoint pointDue = [gestureRecognizer locationOfTouch:1 inView:[gestureRecognizer view]];

    CGPoint point = [gestureRecognizer locationInView:[gestureRecognizer view]];



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

    double minX = plotSpace.xRange.minLimitDouble;
    double maxX = plotSpace.xRange.maxLimitDouble;
    double minY = plotSpace.yRange.minLimitDouble;
    double maxY = plotSpace.yRange.maxLimitDouble;

    //NSLog(@"Scala: %f Gesture Scala %f Velocity: %f",scala,[gestureRecognizer scale],[gestureRecognizer velocity]);
    double lenghtX = maxX - minX;
    double lenghtY = maxY - minY;

    float stepScale = lenghtX/25;

    if ([gestureRecognizer scale] < nextScala) {
        minX = plotSpace.xRange.minLimitDouble - stepScale;
        maxX = plotSpace.xRange.maxLimitDouble + stepScale;
        minY = plotSpace.yRange.minLimitDouble - stepScale;
        maxY = plotSpace.yRange.maxLimitDouble + stepScale;
    }
    else {
        minX = plotSpace.xRange.minLimitDouble + stepScale;
        maxX = plotSpace.xRange.maxLimitDouble - stepScale;
        minY = plotSpace.yRange.minLimitDouble + stepScale;
        maxY = plotSpace.yRange.maxLimitDouble - stepScale;
    }

    lenghtX = maxX - minX;
    lenghtY = maxY - minY;

    NSLog(@"Old X: %f Y: %f",point.x,point.y);
    NSLog(@"New X: %f Y: %f",lenghtX-point.x,lenghtY-point.y);

    if (lenghtX > 0.05 && lenghtX < 4500) {
        plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(minX) length:CPTDecimalFromFloat(lenghtX)];
        plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(minY) length:CPTDecimalFromFloat(lenghtY)];
        nextScala = [gestureRecognizer scale];
    }
}
else if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {

    [self performSelectorInBackground:@selector(getValues) withObject:nil];

// [self getValues];     } }

1 个答案:

答案 0 :(得分:2)

使用此绘图空间方法进行缩放:

-(void)scaleBy:(CGFloat)interactionScale aboutPoint:(CGPoint)interactionPoint;