是什么导致这个不需要的内容插入iOS 8中的UITextView(iOS 7中没有)? [英] What is Causing this Unwanted Content Inset with UITextView in iOS 8 (not there in iOS 7)?
问题描述
我在iOS 7中使用自动布局以编程方式创建 UITextView
。这样的事情:
I've been creating UITextView
s programatically, using auto layout, in iOS 7. Something like this:
_textView = [UITextView new];
_textView.translatesAutoresizingMaskIntoConstraints = NO;
_textView.font = [UIFont systemFontOfSize:18.0];
_textView.delegate = self;
[self.view addSubview:_textView];
除了我创建的其他限制之外,我还有这一个对于文本视图的底部:
In addition to the other constraints I've created, I have this one for the bottom of the text view:
_textViewBottomConstraint =
[NSLayoutConstraint constraintWithItem:_textView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.bottomLayoutGuide
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:0.0];
[self.view addConstraint:_textViewBottomConstraint];
这样我可以在键盘显示时更改约束:
So that I can change the constraint when the keyboard shows:
- (void)keyboardDidShow:(NSNotification*)sender
{
CGRect keyboardFrame =
[sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect convertedFrame =
[self.view convertRect:keyboardFrame fromView:self.view.window];
_textViewBottomConstraint.constant = -convertedFrame.size.height;
[_textView layoutIfNeeded];
}
这一切都很好......
That's all been working fine...
我刚刚切换到Xcode 6和iOS 8(我知道很晚) - 以及<$ c中的文字$ c> UITextView 现在顶部有一个插页。例如。 (文本视图背景为黄色):
I've just switched over to Xcode 6 and iOS 8 (late, I know) - and the text within the UITextView
now has an inset at the top. E.g. (Text view background is yellow):
导致插入的原因是什么?是否连接到 NSTextContainer
和 textContainerInset
?
What's causing the inset? Is it connected to NSTextContainer
and textContainerInset
?
- 正在使用
NSTextContainer
和textContainerInset
使用正确的方式来自iOS 7及更高版本的UITextView
? - 在iOS 8中以 的方式完成吗?
- Is working with
NSTextContainer
andtextContainerInset
the correct way to useUITextView
from iOS 7 and onward? - Does it have to be done that way in iOS 8?
如果是,我会非常感谢以编程方式创建 UITextView
的一些指导以及必要的 NSTextContainer
和 NSLayoutManager
;然后设置 textContainerInset
。 (我将以编程方式使用自动布局。)
If yes, I'd appreciate some guidance for programatically creating a UITextView
along with the necessary NSTextContainer
and NSLayoutManager
; then setting textContainerInset
. (I'll be using auto layout, programatically).
谢谢。
推荐答案
我认为在iOS 8中,selfAdjustsScrollViewInsets的工作方式略有不同。在7中,它仅在控制器的view属性为scrollView时才应用。在8中,它似乎适用于作为控制器视图的子视图的滚动视图。
I think automaticallyAdjustsScrollViewInsets works a bit differently in iOS 8. In 7, it only applied if the controller's view property was a scrollView. In 8, it seems to apply to scroll views that are subviews of the controllers' view.
这篇关于是什么导致这个不需要的内容插入iOS 8中的UITextView(iOS 7中没有)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!