2010-04-22 53 views
0

我有一個UIView與其中的另一個UIView。在裏面的UIView有我要填寫一個文本框當我嘗試以填補它在鍵盤塊我的觀點:鍵盤阻止我的看法

的UIViewController中有以下

containerView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
self.view=containerView; 
//The apropriate releases etc are further on... 

當我觸摸它時,鍵盤按預期方式出現,但會阻止我試圖填充的文本框。如何強制視圖向上滑動?

前視圖

OptionsFront * fv = [[OptionsFront alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
[containerView addSubview:frontView]; 

在正視圖是一個子視圖

CGRect bounds = CGRectMake(0.0f, 210.0f, 280.0f, 130.0f); 
sv = [[UIView alloc] initWithFrame:bounds]; 
[self addSubview:sv]; //added to frontView 

在SV是鈕附近的文本框:

rect = CGRectMake(70.0f, 20.0f, 100.0f, 27.0f); 
cf = [self createTextField_Rounded:rect holder:@"+ve"]; 
[sv addSubview:cf]; 

所以CF恰好是近頁面的底部。我預計當我選擇它時,整個顯示屏會向上移動,但鍵盤只是向上移動並阻止它。

我該怎麼辦?

附錄:

- (UITextField *)createTextField_Rounded:(CGRect) frame holder:(NSString *) ph 
{ 
UITextField *returnTextField = [[UITextField alloc] initWithFrame:frame]; 
returnTextField.borderStyle = UITextBorderStyleRoundedRect; 
    returnTextField.textColor = [UIColor blackColor]; 
returnTextField.font = [UIFont systemFontOfSize:17.0]; 
returnTextField.delegate = self; 
returnTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; 
returnTextField.returnKeyType = UIReturnKeyDone; 

returnTextField.clearButtonMode = UITextFieldViewModeWhileEditing; 

return returnTextField; 
} 

回答

3

你需要移動文本框起來。在你的UITextField委託執行類似(從內存中):

- (void)textFieldDidBeginEditing:(UITextField *)textField { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.3]; 
    textField.superview.frame = CGRectMake(0.0f, 100.0f, 280.0f, 130.0f); // experiment with frame size 
    [UIView commitAnimations]; 
} 

,你會想要將它移回在textFieldDidEndEditing:

+0

謝謝!很優雅的解決方案 – 2010-04-22 18:36:40