2

I have a iPhone app with a CorePlot graph. I would like the user to be able to zoom in and out of the graph similar to the default functionality except for one thing:

  • When the user pinches horizontally -> zoom the x-axis.
  • Vertically -> zoom the y-axis.
  • Diagonally -> zoom both axes.

How can I implement this functionality? Any suggestions would be appreciated.

Thomas
  • 43,637
  • 12
  • 109
  • 140
cduck
  • 2,691
  • 6
  • 29
  • 35

1 Answers1

3

As Felix Khazin shows in in his answer.

The way I do it is by adjusting the PlotSpace

The code is in his answer.

To actually manage the vertica/diagonal/horizontal gestures.

1 Create UIPinchGestureRecognizer

    UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]
                                                      initWithTarget:self action:@selector(handlePinchGesture:)];
            pinchGesture.delegate = self;
            [graphView addGestureRecognizer:pinchGesture];
            [pinchGesture release];

EDIT

2 Implement handlePinchGesture method.

-(IBAction)handlePinchGesture:(UIPinchGestureRecognizer *)sender {

    switch (sender.state) {
        case UIGestureRecognizerStateBegan:
            //Store y and x coordinates of first and second touch
            break;

            case UIGestureRecognizerStateChanged:
            //check y and x coordinates of two finger touches registered in began state
            //to calcualte the actual pinch type:

            //Use scale property to find out if the pinch is zoom in or out

            if([sender scale] < 1) 
                NSLog(@"Zoom out");
            if([sender scale] > 1)
                NSLog(@"Zoom in");

            break;

        default:
            break;
    }
}
Community
  • 1
  • 1
Cyprian
  • 9,423
  • 4
  • 39
  • 73
  • How does each gesture recognizer know if the user's pinch is horizontal, vertical or diagonal? – cduck Jul 15 '11 at 22:07