我有一个UITextView
包含在一个UITableViewCell
。最初显示视图时布局是正确的,但是一旦我单击UITextView
它会自动向上滚动一点,第一行的上半部分字符变得不可见。
这张图是当UITextView
不活跃:
UITextView 不活动 http://gerodt.homeip.net/uitextview-notactive.png http://gerodt.homeip.net/uitextview-notactive.png
这是当我点击UITextView
使其活跃:
UITextView 活动 http://gerodt.homeip.net/uitextview-active.png http://gerodt.homeip.net/uitextview-active.png
我根本不让 UITextView 向上滚动,它应该简单地保持固定。我怎样才能实现这个目标?我已经尝试了几种设置Interface Builder
,但到目前为止还没有运气。
任何建议表示赞赏。
Gero
UITextView 是 UIScrollView 的子类,因此它具有可配置的 contentInset 属性。不幸的是,如果您尝试更改 UITextView 实例上的 contentInset,底部边缘插入总是会重置为 32。我之前在使用短 UITextView 框架时遇到过这种情况,并发现这是一个问题。我怀疑这就是导致您问题的原因,但您应该在调试器中检查 textview 的 contentInset 以确定。
解决方法/解决方案很简单:子类化 UITextView 并重写 contentInset 方法,以便它始终返回 UIEdgeInsetZero。尝试这个:
//
// BCTextView
//
// UITextView seems to automatically be resetting the contentInset
// bottom margin to 32.0f, causing strange scroll behavior in our small
// textView. Maybe there is a setting for this, but it seems like odd behavior.
// override contentInset to always be zero.
//
@interface BCZeroEdgeTextView : UITextView
@end
@implementation BCZeroEdgeTextView
- (UIEdgeInsets) contentInset { return UIEdgeInsetsZero; }
@end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)