iOS TextField输入框点击键盘时随着键盘上移


-(void)textFieldDidBeginEditing:(UITextField *)textField

{

    CGRect frame = textField.frame;

    int offset = frame.origin.y + 70  - (self.view.frame.size.height -216.0);//iPhone键盘高度216,iPad的为352

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

    [UIView setAnimationDuration:0.5f];

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

    if(offset > 0)

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

    [UIView commitAnimations];

//输入框编辑完成以后,将视图恢复到原始状态

-(void)textFieldDidEndEditing:(UITextField *)textField

{

    self.view.frame =CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height);

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM