Xcode/iOS:ビューを埋めるために自動化 - 明示的なフレームサイズが不可欠ですか?

StackOverflow https://stackoverflow.com/questions/4920798

質問

私は欲しいです UITextView それを埋めるために superView, 、これは平野です UIView 内側 UIViewController 実例。

私は作ることができないようです UITextView API指定プロパティを使用してのみこれを行います autoresizingMaskautoresizesSubviews. 。ここに示すようにこれらを設定するには、何もしません。 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 Fuglyですか、誰かが私が間違っていることを説明できますか?最初のフレーム設定コードを自分に持っていることで、問題を克服できると思いました UIViewController サイズを変更します UITextView 一度、そしてその後 autoresizing 必要に応じて動作します。

-(void)viewDidLoad {
    textView.frame = self.view.frame;
}

...しかし、ビューはこの段階で設定されていないように見えますが、「.size」値が定義されていないため、TextViewは小さいままです。

私が欲しいものを達成するための適切な方法は何ですか?フルスクリーンの寸法を介して明示的に指定する必要があります UITextView:initWithFrame その監督を埋めるために?

あなたが提供できるアドバイスに感謝します。

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top