[英]Why UIScrollView does not scroll up when UITextView becomes first responder?
UITextView
becomes first responder when user taps on a button to add a UITextView
on UIScrollView
.当用户点击按钮在
UIScrollView
上添加UITextView
时, UITextView
成为第一响应者。 Actually UIView which contains UITextView
or UITextField
is added in UIScrollView
.实际上包含
UITextView
或UITextField
UIView 添加在UIScrollView
。 When keyboard appears, scrollview does not scroll up, however UITextField
makes it scrolling up when it becomes first responder.当键盘出现时,scrollview 不会向上滚动,但是
UITextField
使它在成为第一响应者时向上滚动。 I register UIKeyboardDidShowNotification
to scroll up.我注册了
UIKeyboardDidShowNotification
来向上滚动。 Below is my code下面是我的代码
- (void)keyboardDidShow:(NSNotification *)notification {
CGRect keyboardEndFrame;
[(notification.userInfo)[UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
NSInteger height = CGRectGetHeight(keyboardEndFrame);
NSInteger lastObj = arrayTotalObjects.count - 1;
UIView *lastView = [arrayTotalObjects objectAtIndex:lastObj];
if(!(lastView.frame.origin.y > height))
return;
UIEdgeInsets inset = originalInset;
inset.bottom += height;
NSLog(@"inset: %f", inset.bottom);
[UIView animateWithDuration:0.3f animations:^{
scrlView.contentInset = inset;
}completion:^(BOOL finished) {
NSLog(@"scrlView inset bottom: %f", scrlView.contentInset.bottom);
}];
}
In this case lastView will be UIView containing UITextView.在这种情况下,lastView 将是包含 UITextView 的 UIView。
This code works for UITextField
but not for UITextView
.此代码适用于
UITextField
但不适用于UITextView
。 How is that possible?这怎么可能? Is it because
UITextView
is subclass of UIScrollView
?是因为
UITextView
是UIScrollView
子类吗?
If someone see this question, The answer is set UITextView scrolling enabled
false
如果有人看到这个问题,答案是 set
UITextView scrolling enabled
false
In lawicko
's answer, I got a hint.在
lawicko
的回答中,我得到了一个提示。 subclass of UIScrollView
. subclass of UIScrollView
。
It works to me.它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.