我有一个带有 CorePlot 图的 iPhone 应用程序。我希望用户能够像默认功能一样放大和缩小图表,除了一件事:
- 当用户水平捏合时 -> 缩放 x 轴。
- 垂直 -> 缩放 y 轴。
- 对角线 -> 缩放两个轴。
我怎样才能实现这个功能?任何建议,将不胜感激。
正如 Felix Khazin 在他的回答中所展示的那样。
我这样做的方法是调整 PlotSpace
代码在他的答案中。
实际管理垂直/对角线/水平手势。
1 创建 UIPinchGestureRecognizer
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePinchGesture:)];
pinchGesture.delegate = self;
[graphView addGestureRecognizer:pinchGesture];
[pinchGesture release];
编辑
2 实现handlePinchGesture 方法。
-(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;
}
}