drawRect and addSubview: custom drawing affects which views?

后端 未结 2 490
灰色年华
灰色年华 2021-02-15 14:14

If I have a custom subclass of UIView that implements drawRect and controller methods use addSubview to create a view hierarchy in this cu

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-15 14:48

    -drawRect: doesn't interact with subviews. It draws whatever the view it's sent to wants to draw in the rect it's given.

    Would it be acceptable to programmatically add and remove subviews within drawRect?

    NO. -drawRect: is for drawing, not for manipulating the view hierarchy.

提交回复
热议问题