在UIView中的Xamarin.iOS项目中,每当需要重绘视图的内容时,就会有一个定期触发并调用SetNeedsDisplay()的事件:
delegate (object sender, EventArgs e)
{
SetNeedsDisplay();
};我还在Draw()的overriden UIView方法中调用了一些Core调用,其代表如下:
public override void Draw(CGRect rect)
{
base.Draw(rect);
using (var context = UIGraphics.GetCurrentContext())
{
// Draw a rectangle of a variable width and height
context.FillRect(new CGRect(0, 0, _width, _height));
}
}按上述事件驱动,SetNeedsDisplay()每秒被调用2-3次.对于_width和_height有不同的值,我希望在屏幕上快速绘制不同大小的矩形,就像调用SetNeedsDisplay()一样。但是,矩形每分钟只能重绘一次或两次。
如何以我想要的频率用核心图形绘制?
发布于 2019-05-24 21:29:06
SetNeedsDisplay()必须从主线程中调用,才能达到预期的效果。上面的事件没有在主线程上运行,因此对SetNeedsDisplay()的调用需要按以下方式调用:
InvokeOnMainThread(() =>
{
SetNeedsDisplay();
});https://stackoverflow.com/questions/56299086
复制相似问题