什么时候调用-[UIView drawRect:]方法? [英] When is -[UIView drawRect:] Method Invoked?

查看:63
本文介绍了什么时候调用-[UIView drawRect:]方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是在显示主视图之前调用它吗?

Is it invoked just before the main view is going to be shown

我们可以在需要时调用它吗?

Can we call it whenever we want?

推荐答案

在需要绘制或重绘视图或视图的一部分时调用它。

It's called whenever the view or part of the view needs to be drawn or redrawn.

首次显示视图时会调用它。更改视图时会调用它。在视图的生命周期中,它可能被称为数百次甚至数千次。例如,在文本视图中,每次输入新的文本字符时都会调用它。

It's called when you first display the view. It's called when you alter the view. In the life cycle of a view, it may be called hundreds or even thousands of times. For example, in a text view, it is called every time a new text character is entered.

程序必须更改视图状态以反映视图的外观,只要调用 setNeedsDisplay 即可触发重绘。在大多数情况下,这种情况会自动发生,但是如果您执行非标准操作,则可能需要自行触发。

Any change in the program state that the view must reflect visually should trigger a redraw by calling setNeedsDisplay. This happens automatically in most cases but you may need to trigger it yourself if you do something non-standard.

这篇关于什么时候调用-[UIView drawRect:]方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆