2014-09-22 130 views
0

我正在使用core-plot繪製一個簡單的散點圖,並且我想在繪圖區域委託「plotAreaWasSelected」時執行某些操作。 當我使用iOS模擬器測試應用程序時,它一切正常,但是當我切換到真正的iOS設備時,從不調用委託方法。我發現核心演示示例具有相同的問題。 有沒有人有同樣的問題?我對此感到困惑,希望有人能夠提供幫助。在設備上運行應用程序時未調用plotAreaWasSelected

我使用的是Xcode 6.0.1,我的設備是iOS7.1,模擬器是iOS8.0。

回答

0

我自己找到了解決方案。
在覈心情節的源代碼,我看到了這一點:

CGPoint lastPoint = self.touchedPoint; 

// omit some codes...... 

// !!!!! the second condition of the if sentence cause my problem !!!!! 
if (CGRectContainsPoint(self.bounds, plotAreaPoint) && CGPointEqualToPoint(plotAreaPoint, lastPoint)) { 
     if ([theDelegate respondsToSelector:@selector(plotAreaTouchUp:)]) { 
      [theDelegate plotAreaTouchUp:self]; 
     } 

     if ([theDelegate respondsToSelector:@selector(plotAreaTouchUp:withEvent:)]) { 
      [theDelegate plotAreaTouchUp:self withEvent:event]; 
     } 

     if ([theDelegate respondsToSelector:@selector(plotAreaWasSelected:)]) { 
      [theDelegate plotAreaWasSelected:self]; 
     } 

     if ([theDelegate respondsToSelector:@selector(plotAreaWasSelected:withEvent:)]) { 
      [theDelegate plotAreaWasSelected:self withEvent:event]; 
     } 

     return NO; // don't block other events in the responder chain 
    } 

在真實設備的環境下,觸摸開始點和觸摸終點通常是彼此不同的,他們總是不一樣的。
所以條件CGPointEqualToPoint(plotAreaPoint, lastPoint)總是假的,if語句中的代碼永遠不會被執行。
爲了適應這一點,我刪除了第二個條件中,如果:

if (CGRectContainsPoint(self.bounds, plotAreaPoint)) { ... } 

它解決了。

+0

我剛剛在[Core Plot](https://github.com/core-plot/core-plot)中解決了這個問題。我改變了你取消的檢查,以便它允許終點距離起點最多5個點,並且仍然激發委託上的選擇方法。 – 2014-09-25 00:50:40

相關問題