1. 程式人生 > >iOS 被鍵盤遮擋時,帶有textfield的tableview自動上移

iOS 被鍵盤遮擋時,帶有textfield的tableview自動上移

- (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];
    }
}