CorePlotグラフを備えたiPhoneアプリがあります。次の1つを除いて、デフォルトの機能と同様に、ユーザーがグラフをズームインおよびズームアウトできるようにしたいと思います。
- ユーザーが水平方向にピンチしたとき->x軸をズームします。
- 垂直方向->y軸をズームします。
- 対角線->両方の軸をズームします。
この機能を実装するにはどうすればよいですか?任意の提案をいただければ幸いです。
フェリックス・カジンが彼の答えに示しているように。
私のやり方は、PlotSpaceを調整することです
コードは彼の答えにあります。
垂直/対角/水平ジェスチャを実際に管理します。
1UIPinchGestureRecognizerを作成します
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePinchGesture:)];
pinchGesture.delegate = self;
[graphView addGestureRecognizer:pinchGesture];
[pinchGesture release];
編集
2handlePinchGestureメソッドを実装します。
-(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;
}
}