这是我的代码:
-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2]; // if you want to slide up the view
[UIView setAnimationBeginsFromCurrentState:YES];
CGRect rect = scroll.frame;
if (movedUp)
{
rect.size.height += kOFFSET_FOR_KEYBOARD;
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
}
else
{
rect.size.height -= kOFFSET_FOR_KEYBOARD;
rect.origin.y += kOFFSET_FOR_KEYBOARD;
}
scroll.frame = rect;
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)notif {
[self setViewMovedUp:NO];
}
- (void)keyboardWillShow:(NSNotification *)notif{
[self setViewMovedUp:YES];
}
- (void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:self.view.window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:self.view.window];
}
- (void)viewWillDisappear:(BOOL)animated
{
// unregister for keyboard notifications while not visible.
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
问题是,我怎样才能将它指定为仅适用于 TextView3,而不适用于 TextView2 或 TextView1。背景是,TextView1 和 TextView2 不需要,因为在我的视图之上。只有 TextView3 是不可读的 TextView,因为键盘被覆盖并且必须更正视图才能阅读我写的内容。