点击textField出现键盘是屏幕上移

只需将下面代码加入delegate中的适当位置即可

#pragma mark - UITextViewDelegate

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    textView.text = @"";
    NSTimeInterval animationDuration = 0.30f;

    [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];

    [UIView setAnimationDuration:animationDuration];

    float width = self.view.frame.size.width;

    float height = self.view.frame.size.height;

    CGRect rect = CGRectMake(0.0f, -60.0f,width,height);

    self.view.frame = rect;

    [UIView commitAnimations];
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    if ([textView.text length] == 0) {
        textView.text = @"Comment...";
    }
    NSTimeInterval animationDuration = 0.30f;

    [UIView beginAnimations:@"ResizeForKeyboard"context:nil];

    [UIView setAnimationDuration:animationDuration];

    CGRect rect = CGRectMake(0.0f, 20.0f, self.view.frame.size.width, self.view.frame.size.height);

    self.view.frame = rect;

    [UIView commitAnimations];
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注