【问题标题】:Core Plot Real Time interaction with UIButton .setTextCore Plot 与 UIButton .setText 的实时交互
【发布时间】:2020-05-10 15:31:55
【问题描述】:

Core Plot Realtime 有一个奇怪的问题。我有一个 UIButton 可以启动和停止一个更新绘图数据的计时器。我确实保留了以前点的历史记录,并且只显示最后 150 个值。这一切都很好。现在,当我根据定时器打开并将其设置为关闭来更改 UIButton 的文本时,绘图将重置为其初始的前 150 个值。当我重新启动计时器时,它会从数据结束时停止的地方开始。代码如下所示:

@IBOutlet weak var pause: UIButton!

@IBAction func pausePlay() {
    if isPaused  {
        startGraphUpDates()
        isPaused = false
        pause.setTitle("⏸", for: .normal)

    } else {
        stopGraphUpDates()
        isPaused = true
        pause.setTitle("▶️", for: .normal) // This is the statement that seems to cause the problem.
     }
}

任何想法将不胜感激

【问题讨论】:

  • 是在初始化期间将isPaused 设置为true 还是定时器立即启动? startGraphUpDates()stopGraphUpDates() 中的代码是什么?
  • isPaused 在声明为时被初始化: var isPaused: Bool = false 当 ViewController 加载时。 startTimer() 函数在 viewDidLoad() 中调用,我看到我正在 viewDidLayoutSubviews() 中设置绘图。以下是用于启动和停止用于更新绘图的计时器的函数:
  • func startGraphUpDates() { // 设置定时器更新图 self.graphUpdateTimer = Timer.scheduledTimer(timeInterval: (1.0 / frameRate), target: self, selector: #selector(newData), userInfo :无,重复:真)}func stopGraphUpDates(){self.graphUpdateTimer.invalidate()}

标签: core-plot


【解决方案1】:

这是一个简单的修复。我正在初始化情节:

override func viewDidLayoutSubviews() {
  super.viewDidLayoutSubviews()
  initPlot()
}

我应该在以下位置初始化绘图:

override func viewDidLoad() {
  super.viewDidLoad()
  initPlot()
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-26
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多