你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS TextField輸入框點擊鍵盤時隨著鍵盤上移

iOS TextField輸入框點擊鍵盤時隨著鍵盤上移

編輯:IOS開發綜合

-(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);

}

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved