1. 程式人生 > >iOS UITextField輸入框隨鍵盤彈出介面上移

iOS UITextField輸入框隨鍵盤彈出介面上移

//點選輸入框介面跟隨鍵盤上移

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

CGRect frame = textField.frame;

int offSet = frame.origin.y + 70 - (self.view.frame.size.height - 216.0); //iphone鍵盤高度為216.iped鍵盤高度為352

    [UIViewbeginAnimations:@"ResizeForKeyboard"context:nil];

    [UIViewsetAnimationDuration

:0.5f];

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

if (offSet > 0) {

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

        [UIViewcommitAnimations];

    }

}

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

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

self

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

}