键盘弹出后,输入框自动弹到最顶部

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

{

    UIScrollView *scrollView = (UIScrollView *)[self.view viewWithTag:WIN_TAG_SCROLLVIEW];

    _currEditY = scrollView.contentOffset.y;

    

    CGPoint point = scrollView.contentOffset;

    point.y = textField.frame.origin.y - 8 - scrollView.contentInset.top;

    scrollView.contentOffset = point;

    

    return YES;

}

 

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField

{

    UIScrollView *scrollView = (UIScrollView *)[self.view viewWithTag:WIN_TAG_SCROLLVIEW];

    CGPoint point = scrollView.contentOffset;

    point.y = _currEditY;

    scrollView.contentOffset = point;

    

    return YES;

}

posted on 2015-01-21 08:59  trako  阅读(254)  评论(0编辑  收藏  举报

导航