【问题标题】:Using NSTimer to call SetNeedsDisplay in Xamarin for iOS使用 NSTimer 在 Xamarin for iOS 中调用 SetNeedsDisplay
【发布时间】:2013-06-14 00:43:56
【问题描述】:

我有一个 UIView,它从缓冲区获取数据(变化的)并绘制它。我希望屏幕更新为 10Hz。 UIView 被称为窗格,这就是我在 ViewController 中调用它的方式:

        //create graphics to display data
        GraphPane pane = new GraphPane ();
        pane.Frame = UIScreen.MainScreen.Bounds;
        Add (pane); 

        //setup timer to update pane
        NSTimer timer = NSTimer.CreateRepeatingTimer (0.1, delegate {pane.SetNeedsDisplay ();});

这不起作用(从不调用 Pane.Draw),而且我还没有找到一个很好的例子来说明如何做到这一点。任何建议表示赞赏。

【问题讨论】:

  • timer 超出范围时是否被释放?
  • 我实际上将计时器定义为类变量,所以它不应该。

标签: c# objective-c nstimer xamarin setneedsdisplay


【解决方案1】:
        timer = NSTimer.CreateRepeatingScheduledTimer (TimeSpan.FromSeconds (0.1), delegate {
            pane.SetNeedsDisplay ();
        });

解决了我的问题。

【讨论】:

  • 更改是从 CreateReapeatingTimer 到 CreateRepeatingScheduledTimer - 似乎默认情况下没有安排。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多