我在這裏有一些問題。我有一個UITextView,當我點擊裏面的時候被鍵盤取消,所以,我想在這裏做的是一個UIScrollView,它允許我看到我在TextView中寫的內容...問題與UIScrollView和UIKeyboard
這是到目前爲止我的代碼:
-(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的視圖,而不是往上走,它的股價下跌......
任何想法?
不,你不明白的問題,我的問題是,鍵盤解僱的UITextView被調用的時候......我wan't滾動整個的UIView該鍵盤不解僱我的TextView ... – Marnerk
你的意思是鍵盤**是覆蓋**你的文字視圖?對於鍵盤無法消除文本視圖,只能反過來:P。 – Mundi