0

我有一个缩放手势的问题,主要问题是当我缩放时我缩放视图的中心,所以如果我在右上角或底部捏缩放总是在视图的中心。这是我的代码,我如何编辑它以在捏触摸中间进行缩放?

- (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];

// [自我获取值]; } }

4

1 回答 1

2

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

-(void)scaleBy:(CGFloat)interactionScale aboutPoint:(CGPoint)interactionPoint;
于 2013-05-01T01:06:48.660 回答