iOS UITextField,UITextView鍵盤遮擋問題

//開始編輯輸入框的時候,軟鍵盤出現,執行此事件

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

    CGRect frame = textField.frame;

    int offset = frame.origin.y + 100 - (Height - 360.0);//鍵盤高度

    NSTimeInterval animationDuration = 0.30f;

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

    [UIView setAnimationDuration:animationDuration];

    

    //將視圖的Y座標向上移動offset個單位,以使下面騰出地方用於軟鍵盤的顯示

    if(offset > 0)

        self.view.frame = CGRectMake(0.0f, -offset, Width, Height);

    [UIView commitAnimations];

}

//輸入框編輯完成以後,將視圖恢復到原始狀態

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

    self.view.frame =CGRectMake(0, 0, Width, Height);

}


發佈了25 篇原創文章 · 獲贊 0 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章