弹出键盘,文本框的移动

//输入文字时。文本框上移,适应键盘的高度

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

{

    //    NSLog(@"将要开始编辑");

    CGFloat offSet = self.view.frame.size.height - 216;

    NSLog(@"aaaa = %f", offSet);

    if (offSet <= 0) {

        [UIView animateWithDuration:0.5 animations:^{

            

            CGRect frame = self.view.frame;

            frame.origin.y = offSet;

            self.view.frame = frame;

            

        }];

    }

    return YES;

}

//回收键盘时,文本框回到原来位置

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField

{

    //    NSLog(@"将要结束编辑");

    [UIView animateWithDuration:0.5 animations:^{

        

        CGRect frame = self.view.frame;

        frame.origin.y = 0.0;

        self.view.frame = frame;

    }];

    NSLog(@"dd");

    return YES;

}

 

posted @ 2015-12-25 18:22  xiaolingling  阅读(183)  评论(0)    收藏  举报