`
wang_peng1
  • 浏览: 3942488 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

UITextField 键盘弹出移动

 
阅读更多
//Code from Brett Schumann
-(void) keyboardWillShow:(NSNotification *)note{
    
    
    NSDictionary* info = [note userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    
    CGRect frame = self.view.frame;
    frame.size.height -= kbSize.height;
    CGPoint fOrigin = self.nameTextField.frame.origin;
    fOrigin.y -= self.scrollView1.contentOffset.y;
    fOrigin.y += self.nameTextField.frame.size.height;
    if (!CGRectContainsPoint(frame, fOrigin) ) {
        CGPoint scrollPoint = CGPointMake(0.0, self.nameTextField.frame.origin.y + self.nameTextField.frame.size.height - frame.size.height);
        [self.scrollView1 setContentOffset:scrollPoint animated:YES];
    }
    
    
   
}


-(void) keyboardWillHide:(NSNotification *)note{
    // get keyboard size and location
    [self.scrollView1 setContentOffset:CGPointZero animated:YES];
}


//系统通知 当键盘中英文切换时的事件
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    //系统通知 当键盘隐藏时的事件
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics