私は 2 つの UITextViews を持っています。1 つは UIView の上部にあり、もう 1 つは UIView の下部にあります。
このコードを使用して、キーボードが表示されたときに UIView を移動します。
- (void) viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide)
name:UIKeyboardWillHideNotification
object:nil];
}
-(void)keyboardWillShow {
// Animate the current view out of the way
[UIView animateWithDuration:0.3f animations:^ {
self.frame = CGRectMake(0, -160, 320, 480);
}];
}
-(void)keyboardWillHide {
// Animate the current view back to its original position
[UIView animateWithDuration:0.3f animations:^ {
self.frame = CGRectMake(0, 0, 320, 480);
}];
}
下から UITextView を使用するとうまくいきます。しかし、私の問題は、UIViewのトップからUITextViewを使用したい場合、キーボードが表示され、UIViewが上に移動しますが、トップのUITextViewも上に移動します。ユーザーがUITextViewにテキストを上から入力したい場合、UIViewを移動したくありません。