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