0
我有一個帶有文本框的uiviewcontroller。當點擊底部的文本字段時,該字段被鍵盤覆蓋,當您單擊文本字段時,如何使其「滾動」。或者只是有它這樣的UIViewController可以滾動當鍵盤出現時,UIViewController向上移動
我有一個帶有文本框的uiviewcontroller。當點擊底部的文本字段時,該字段被鍵盤覆蓋,當您單擊文本字段時,如何使其「滾動」。或者只是有它這樣的UIViewController可以滾動當鍵盤出現時,UIViewController向上移動
嘗試把你的觀點的所有文本框的滾動型裏面,然後讓你的視圖控制器符合UITextFieldDelegate和UINavigationControllerDelegate。
定義您viewController.m以下方法
-(IBAction)textFieldDidBeginEditing:(UITextField *)sender // connect all textfields in your view to this method
{
sender.delegate = self;
}
//called when UIKeyboardDidShowNotification is sent.
-(void)keyboardWasShown:(NSNotification *)aNotification
{
NSDictionary * info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey]CGRectValue].size;
[self.scrollView setContentOffset:CGPointMake(0, kbSize.height) animated:YES];
}
// Called when the UIKeyboardWillHideNotification is sent,method is called when the keyboard is closed. It returns the scroll view to its original position.
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
[self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}
//This method is called when you have finished editing a text field.
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
return [textField resignFirstResponder];
}
將這個在viewDidLoad中:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.scrollView.scrollEnabled = YES;
self.automaticallyAdjustsScrollViewInsets = YES;
}
這可能做的伎倆... HTH :)
谷歌「的UIViewController當鍵盤出現時向上移動「 – Logan