UIScrollView中的UITextField键盘遮挡问题的最简单解决办法 2012-10-31 15:10 1743人阅读 评论(0) 收藏 举报 两步: 1重载textFieldDidBe

两步:

1重载textFieldDidBeginEditing


- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    foucsTextField = textField;
    s_mainScrollView.contentSize = CGSizeMake(__SCREEN_WIDTH,__SCREEN_HEIGHT +216);//原始滑动距离增加键盘高度
    CGPoint pt = [textField convertPoint:CGPointMake(0, 0) toView:s_mainScrollView];//把当前的textField的坐标映射到scrollview上
    if(s_mainScrollView.contentOffset.y-pt.y+NAVIGATION_BAR_HEIGHT<=0)//判断最上面不要去滚动
        [s_mainScrollView setContentOffset:CGPointMake(0, pt.y-NAVIGATION_BAR_HEIGHT) animated:YES];//华东


}

2:重载textFieldShouldReturn

- (BOOL)textFieldShouldReturn:(UITextField*)theTextField
{
    {
        [theTextField resignFirstResponder];
        
        //开始动画 
        [UIView beginAnimations:nil context:nil];  
        //设定动画持续时间 
        [UIView setAnimationDuration:0.3];
        s_mainScrollView.frame = CGRectMake(0, NAVIGATION_BAR_HEIGHT, __SCREEN_WIDTH, __SCREEN_HEIGHT);
        s_mainScrollView.contentSize = CGSizeMake(__SCREEN_WIDTH,__SCREEN_HEIGHT);
        //动画结束 
        [UIView commitAnimations]; 
        
       
    }
    return YES;
}

你可能感兴趣的:(UIScrollView中的UITextField键盘遮挡问题的最简单解决办法 2012-10-31 15:10 1743人阅读 评论(0) 收藏 举报 两步: 1重载textFieldDidBe)