私のアプリケーションのテキストビューで次のコードを使用しています。私はキーボードがキーボードの上に表示され、キーボードとテキストビューの外側をクリックすると、キーボードが閉じられるようにキーボードをトリガーすると、そのようにしました。私が抱えている問題は、テキストビューをクリックするとテキストビューの遅延が約5秒間キーボードの上を移動し、ポップアップし、キーボードを閉じるとすぐに消えてしまい、すぐに消えてしまいますキーボードが開きます。私はこれを修正し、ジャンプの代わりに開閉するので、キーボードの上を移動するビューをアニメーション化する方法はありますか?ユージンZaychenkoが示唆するようおUIKeyboardWillShowNotification
使用できる遅延の問題については目的Cキーボードで移動していないビュー
おかげ
- (void)viewDidLoad
{
[super viewDidLoad];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(didShow:) name:UIKeyboardDidShowNotification object:nil];
[center addObserver:self selector:@selector(didHide) name:UIKeyboardWillHideNotification object:nil];
_theTextView.delegate = self;
_theTextView.text = @"Type your message..";
_theTextView.textColor = [UIColor lightGrayColor]; //optional
_theTextView.layer.cornerRadius = 5;
_theTextView.layer.masksToBounds = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
}
-(void)dismissKeyboard {
[_theTextView resignFirstResponder];
}
- (void)didShow:(NSNotification *)notification
{
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
self.textViewPOS.constant = keyboardSize.height;
NSLog(@"Opened");
}
- (void)didHide
{
self.textViewPOS.constant = 0;
NSLog(@"Closed");
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(@"typing");
return YES;
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
if ([textView.text isEqualToString:@"Type your message.."]) {
textView.text = @"";
textView.textColor = [UIColor blackColor]; //optional
}
[textView becomeFirstResponder];
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
if ([textView.text isEqualToString:@""]) {
textView.text = @"Type your message..";
textView.textColor = [UIColor lightGrayColor]; //optional
}
[textView resignFirstResponder];
}
@end
UIKeyboardWillShowNotificationを使用しようとしましたか? –
@EugeneZaychenkoそれはすぐにうまく動作しますが、キーボードの開閉の速さでビューをアニメーション化する方法はありますか?今はちょうどその位置にジャンプするので、キーボードは追いつく。 –
このコードの前に、self.textViewPOS.constant = keyboardSize.height; [UIView animateWithDuration:0.25アニメーション:^ { [self.view layoutIfNeeded]; }完了:^(BOOL終了){ }]; –