我有一个带有 CorePlot 图表的 iPhone 应用程序。我希望用户能够像默认功能一样放大和缩小图表,除了一件事:
- 当用户水平捏合时 -> 缩放 x 轴。
- 垂直 -> 缩放 y 轴。
- 对角线 -> 缩放两个轴。
如何实现此功能?如有任何建议,我们将不胜感激。
最佳答案
正如 Felix Khazin 在他的 answer 中所显示的那样.
The way I do it is by adjusting the 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;
}
}
关于iphone - CorePlot 缩放轴独立于多点触控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6713206/