我有一個iPhone應用程序。該視圖由兩個子項組成:tableview 400像素高,視圖底部的uitextview高約80像素。iphone:如何調整視圖及其所有子項的大小(在鍵盤彈出的情況下)?
我想在鍵盤可見時向上移動textview和tableview。我調整了「主要」視圖以使其更小。爲什麼它的孩子也不會調整大小? 我是否需要重新調整tableview的框架,並重新調整textview的框架?我只是想知道預期的行爲是什麼。我是否需要使用setNeedsLayout()或setNeedsDisplay?
我預計,通過縮小「主要」視圖,它的孩子將會「收縮」並受到其父視圖的限制。它看起來像文本視圖保持在屏幕的底部。 tableview看起來是正確的(收縮),但textview看起來不像它移動。雖然在新的縮小視圖中,現在有一個白色區域,其中文本視圖應該移動到。
// Called when the UIKeyboardDidShowNotification is sent.
- (空)keyboardWasShown:(NSNotification *)aNotification {
NSLog(@"keyboard was shown");
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
//CGRect keyboardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];
NSLog(@"kb size is:%f",kbSize.height);
//UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
CGRect newFrame = self.view.frame;
//20 status bar height, 44 is nav bar height
newFrame.size.height = 480 -20 - 44 - kbSize.height;
self.view.frame = newFrame;
self.view.layer.borderWidth = 1.0f;
self.view.layer.borderColor = [[UIColor redColor] CGColor];
[self.view setNeedsLayout];
[self.view setNeedsDisplay];
}