2014-09-22 132 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

相关问题