ios中怎么处理键盘挡住输入框

//此前要遵循UITextFieldDelegate代理。并且设置该文本框为当前控制器的代理

//开始编辑的时候让整个view的高度网上移动
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [UIView animateWithDuration:0.3f animations:^{
        CGRect curframe = self.view.frame; //不能直接修改frame的y值。需要先将其取出,然后再赋值回去
        curframe.origin.y -= 70;
        self.view.frame = curframe;
    }];
    
}

//当结束编辑的时候,又将整个view退回到原来的位置
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [UIView animateWithDuration:0.3f animations:^{
        CGRect curframe = self.view.frame;
        curframe.origin.y += 70;
        self.view.frame = curframe;
    }];
}

 

posted @ 2014-02-23 17:45  —__MOMO__—  阅读(401)  评论(0编辑  收藏  举报