インスタンス内のプレーンである、UITextView
を埋めたいのですが。superView
UIView
UIViewController
とUITextView
のAPI指定のプロパティだけを使用してこれを行うことはできないようです。ここに示すようにこれらを設定しても何も起こりません。画面いっぱいに表示されても、小さいままです。autoresizingMask
autoresizesSubviews
UITextView
superView
// use existing instantiated view inside view controller;
// ensure autosizing enabled
self.view.autoresizesSubviews = YES;
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|
UIViewAutoresizingFlexibleWidth;
// create textview
textView = [[[UITextView alloc] autorelease] initWithFrame:CGRectMake(0, 0, 1, 1)];
// enable textview autoresizing
[textView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleHeight];
// add textview to view
[self.view addSubview:textView];
ただし、View Controller内で独自のビューをインスタンス化し、その'.view'プロパティを置き換えると、すべてが期待どおりに機能し、textViewがそのスーパービューを埋めます。
// reinstantiate view inside view controller
self.view = [[UIView alloc]init];
// create textview
textView = [[[UITextView alloc] autorelease] initWithFrame:CGRectMake(0, 0, 1, 1)];
// enable textview autoresizing
[textView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleHeight];
// add textview to view
[self.view addSubview:textView];
これらすべてのイニシャライザー/メソッド内で両方のコードチャンクを試しましたが、すべての場合に同じ状況が発生します。
-(id)init;
-(id)initWithFrame:(CGRect)frame;
-(void)viewDidLoad;
の「.view」を復元するのUIViewController
は醜いことだと思いますが、私が間違っていることを誰かが説明できますか?最初のフレーム設定コードを1回UIViewController
サイズ変更することで問題を解決できUITextView
、その後autoresizing
は希望どおりに動作すると思いました。
-(void)viewDidLoad {
textView.frame = self.view.frame;
}
...しかし、この段階ではview.frameが設定されていないようです。また、'。size'値が定義されていないため、textViewは小さいままです。
私が望むことを達成するための適切な方法は何ですか?UITextView:initWithFrame
スーパービューを埋めるために、を介してフルスクリーンのサイズを明示的に指定する必要がありますか?
アドバイスをいただければ幸いです。