我这里有一些问题。我有一个 UITextView,当我点击里面时,它会被键盘关闭,所以,我在这里要做的是一个 UIScrollView,它让我可以看到我在 TextView 中写的内容......
到目前为止,这是我的代码:
-(void)keyboardWillShow {
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
-(void)keyboardWillHide {
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView animateWithDuration:.3 animations:^{
CGRect rect = self.view.frame;
if (movedUp)
{
scrollView.contentSize = CGSizeZero;
scrollView.frame = CGRectMake(0, 80, 320, 308);
// rect.origin.y -= kOFFSET_FOR_KEYBOARD;
// rect.size.height += kOFFSET_FOR_KEYBOARD;
}
else
{
scrollView.contentSize = CGSizeZero;
scrollView.frame = CGRectMake(0, 190, 320, 308);
// rect.origin.y += kOFFSET_FOR_KEYBOARD;
// rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
self.view.frame = rect;
}];
}
- (void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
问题是代码不能正常工作,当我点击 textView 视图而不是上升时,它下降了......
有任何想法吗?