1. 程式人生 > >iOS UITextView 隨鍵盤彈出介面上移

iOS UITextView 隨鍵盤彈出介面上移

- (void)textViewDidBeginEditing:(UITextView *)textView {

    CGRect frame = textView.frame;

    int offSet = frame.origin.y + 70 - (self.view.frame.size.height - 216.0); //iphone鍵盤高度為216.iped鍵盤高度為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)textViewDidEndEditing:(UITextView *)textView {

self.view.frame = CGRectMake(

0, 0, self.view.frame.size.width, self.view.frame.size.height);

}