iPhone SDK:如何在方向更改后触发UIView子类上的drawRect?

问题描述:

我正在继承UIView并覆盖drawRect方法。我注意到只在视图首次加载时才调用视图的drawrect。之后再也不会被召唤了。如何确保在方向更改后调用它?我已经尝试在旋转之前和之后调用setNeedsDisplay,但是没有这样做。

I am subclassing a UIView and overwrite the drawRect method. I'm noticing that the view's drawrect is only being called when the view first loads. After that it is never called again. How to I make sure it gets called after an orientation change? I've tried calling setNeedsDisplay on the view before and after the rotation and that doesn't do it.

[myView setContentMode:UIViewContentModeRedraw];

你也可以在IB中设置它(即设置模式为重绘)

You can set this in IB as well (i.e., set mode to "redraw")