Bạn nên sử dụng thông báo keyboardWillShow
: để điều chỉnh các khung chế độ xem khác.
Thông báo được đăng lên keyboardWillShow
: không chỉ trên becomeFirstResponder
cho TextView/Field mà còn khi người dùng hiển thị/ẩn bàn phím loại nhanh.
sau khi keyboardWillShow
: thông báo đã được đăng, khung của bàn phím có thể được chụp bởi UIKeyboardFrameEndUserInfoKey
trong đối tượng thông báo.
Một ví dụ về textView
rằng điều chỉnh khung của nó dựa trên bàn phím:
- (void)keyboardWillShow:(NSNotification *)notification
{
CGRect keyboardRect = [[[notification userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationCurve curve = [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
[UIView animateWithDuration:duration animations:^{
[UIView setAnimationCurve:curve];
self.textViewVisualEffectView.frame = CGRectMake(self.textViewVisualEffectView.origin.x, self.view.height - keyboardRect.size.height - self.textViewVisualEffectView.height, self.textViewVisualEffectView.width, self.textViewVisualEffectView.height);
} completion:^(BOOL finished) {
}];
}
Hãy nhìn vào giải pháp của tôi trong liên kết: http://stackoverflow.com/questions/26213681/ios-8- keyboard-hides-my-textview/26226732 # 26226732 –