Reputation: 2691
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:
How can I implement this functionality? Any suggestions would be appreciated.
Upvotes: 2
Views: 1622
Reputation: 9453
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;
}
}
Upvotes: 3