2011-01-15 17 views
0

私はUITextViewを使ってテキストビュー(nib-file)を作成し、ビュー全体を最大化しました。UITextViewはキーボードの表示に合わせてサイズ変更しません

これまでにviewcontrollerをnavigationcontrollerにプッシュすると、キーボードはテキストビューのviewDidLoadメソッドでロードされます。

私の問題は、スペースがあるよりも多くの行を含むテキストを書き込むと、テキストがキーボードの後ろにあるということです。私はアップルhereからのsampeをたどった。

"newTextViewFrame"を記録するとNULLになります。しかし、私はそれを良い値を持っているものをデバッグする場合。 ハードコーディングしても、UITextViewはサイズを変更しません。

- (void)keyboardWillShow:(NSNotification *)notification { 

/* 
Reduce the size of the text view so that it's not obscured by the keyboard. 
Animate the resize so that it's in sync with the appearance of the keyboard. 
*/ 

NSDictionary *userInfo = [notification userInfo]; 

// Get the origin of the keyboard when it's displayed. 
NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; 

// Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position. 
CGRect keyboardRect = [aValue CGRectValue]; 
keyboardRect = [self.view convertRect:keyboardRect fromView:nil]; 

CGFloat keyboardTop = keyboardRect.origin.y; 
CGRect newTextViewFrame = self.view.bounds; 
newTextViewFrame.size.height = keyboardTop; - (self.view.bounds.origin.y); 

// Get the duration of the animation. 
NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; 
NSTimeInterval animationDuration; 
[animationDurationValue getValue:&animationDuration]; 

// Animate the resize of the text view's frame in sync with the keyboard's appearance. 
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:animationDuration]; 

createListingTextView.frame = newTextViewFrame; 

[UIView commitAnimations]; 
NSLog(@"Textview resized: %@", newTextViewFrame); 

}

私の仕事私の単純な:

は、ここに私のコードですUITextView、オープンキーボード付きビューを実装し、テキストを超えたときに、これまでUITextViewをスクロールします。

してくださいアドバイスは...セミコロンは、これは確かに調整した高さを得ることからnewTextViewFrameを妨げるライン

newTextViewFrame.size.height = keyboardTop; - (self.view.bounds.origin.y); 

にkeyboardTop後

答えて

1

があります。

+0

Woops。私の間違い。私はsomテスト目的のためにセミコロンをそこに置いた。問題は依然として続きます。私の設定で何とか再描画されたUITextViewのようです。 IBでサイズを小さくしても、View iが表示されるときにUITextViewが最大化されます。 – esbenr

+0

奇数明白な質問をしなければなりません:あなたは正しいnibファイルを変更していますか?あなたは清潔で再建を試みましたか? – Daniel

+0

ええと私は実際にAppleからの例をコピー貼り付けしようとしましたが、それでもサイズを変更することはできません。デザイナーでTextAreaのサイズをさまざまな小さなものに設定しても、そのアプリケーションを実行すると「最大」になります。私は上記のコードはうまくいくはずですが、実行時に領域を最大化する何かが欠けています。私は仕事から家に帰るときにコード全体を削除します。 – esbenr

関連する問題