2011-07-15 54 views
2

我有一個帶有CorePlot圖形的iPhone應用程序。我希望用戶能夠放大和縮小類似於默認功能的圖表,除了一件事情:CorePlot通過多點觸控獨立縮放軸

  • 當用戶捏住水平 - >縮放x軸。
  • 垂直 - >縮放y軸。
  • 對角線 - >縮放兩個軸。

我該如何實現此功能?任何建議,將不勝感激。

回答

3

Felix Khazin在他的answer中顯示。

我做的方式,它是通過調整PlotSpace

的代碼是他的回答。

實際管理垂直/對角線/水平手勢。

1創建UIPinchGestureRecognizer

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

EDIT

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; 
    } 
} 
+0

每個手勢識別器如何知道用戶的捏是水平的,垂直的還是對角線的? – cduck

+0

檢查我的編輯,我改變了代碼 – Cyprian