iOS 被键盘遮挡时,带有textfield的tableview自动上移

来源:互联网 发布:andrew marc牌子知乎 编辑:程序博客网 时间:2024/04/30 11:05
- (void)textFieldDidBeginEditing:(nonnull UITextField *)textField{
    UITableViewCell * cell=(UITableViewCell *)[[textField  superview] superview];
    NSIndexPath *indexPath=[self.myTableView indexPathForCell:cell];
    if (indexPath.section==0) {
        
    }else {
        [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
        [UIView setAnimationDuration:0.30f];
        _point = self.myTableView.center;
        self.myTableView.center = CGPointMake(SCREENSIZE.width, 120);
        [UIView commitAnimations];
    }
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    UITableViewCell * cell=(UITableViewCell *)[[textField  superview] superview];
    NSIndexPath *indexPath=[self.myTableView indexPathForCell:cell];
    if (indexPath.section==0) {
        
    }else {
        [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
        [UIView setAnimationDuration:0.30f];
        self.myTableView.center = _point;
        [UIView commitAnimations];
    }
}
0 0
原创粉丝点击