drawRect:
を使用して図形を描画しています。私はこのメソッドを呼び出して、方向が変わったときに形状を再描画する必要があります。が呼び出されたときに自動的にdrawRect:
を呼び出す方法があると思いました。drawRectを呼び出す方法:layoutSubviewsがiosで呼び出すとき
ありがとうございます。それだ
This method is called when a view is first displayed or when an event occurs that invalidates a visible part of the view. You should never call this method directly yourself. To invalidate part of your view, and thus cause that portion to be redrawn, call the setNeedsDisplay or setNeedsDisplayInRect: method instead.
:UIViewクラスの参照https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/drawRectから
私が 'init:'に 'contentMode'を設定しても動作しないのですが、代わりに他の方法で設定する必要がありますか? –
@SunilRaoあなたの 'init'は呼び出されていますか(ブレークポイントを設定しますか?ほとんどの場合、 'UIView'サブクラスでは、' init'の代わりに 'initWithFrame:'をオーバーライドする必要があります.' init'の 'UIView'実装は' initWithFrame:CGRectZero'を呼び出すだけです。また、 'autoresizingMask'をチェックして、回転時にビューの境界(幅または高さ)を変更することを確認してください。そして、いいえ、一定の一回限りの設定であるため、初期化子に 'contentMode'を設定する必要があります。 – Hamish
それは完璧に機能しました。 –