关闭

textFied随着键盘移动

119人阅读 评论(0) 收藏 举报
分类:

-(void)textFieldDidBeginEditing:(UITextField *)textField{

    [self animatetextField:textField up:YES];

}

-(void)textFieldDidEndEditing:(UITextField *)textField{

     [self animatetextField:textField up:NO];

}


-(void)animatetextField:(UITextField*)textField up:(BOOL)isUp{

    CGRect frame = textField.frame;

    int offset;

    if (isUp) {

          offset = frame.origin.y + 70 - (self.view.frame.size.height - 231);

    }else{

        offset = 0;

    }

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

    [UIView setAnimationDuration:0.3f];

    //将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示

    self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height);

    [UIView commitAnimations];

}



-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.textField resignFirstResponder];

}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:48336次
    • 积分:1397
    • 等级:
    • 排名:千里之外
    • 原创:80篇
    • 转载:91篇
    • 译文:0篇
    • 评论:3条
    最新评论