What causes this nondescript paste of content with a UITextView in iOS 8 (not in iOS 7)?

I created a UITextView programmatically using an automatic 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 restrictions I created, I have this 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 I can change the restriction when the keyboard displays:

 - (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]; } 

So that everything works fine ...

Problem

I just switched to Xcode 6 and iOS 8 (late, I know) - and the text in the UITextView now has an insert at the top. For example. (Background of the text image is yellow):

enter image description here

What causes the insert? Is it NSTextContainer to NSTextContainer and textContainerInset ?

  • Works with NSTextContainer and textContainerInset correct way to use UITextView from iOS 7 onwards
  • Does it have to do this in iOS 8?

If so, I would appreciate some recommendations for programmatically creating a UITextView along with the necessary NSTextContainer and NSLayoutManager ; then set textContainerInset . (I will use automatic linking, programmatically).

Thanks.

+5
ios7 ios8 uitextview nslayoutmanager nstextcontainer
source share
2 answers

I think that automatically AdjustsScrollViewInsets works differently in iOS 8. In 7, it only applies if the controller view property was scrollView. In 8, this seems to apply to scroll views, which are sub-views of controllers.

+9
source share

This is the contentInset of the UIViewController .

It seems that with iOS 8, with my UITextView , as in my UIViewController , you need to explicitly set:

 self.automaticallyAdjustsScrollViewInsets = NO; 

I don’t explicitly install this, I checked the difference between the physical iPhone 5s running iOS 7 and the Simulator iPhone 5s with iOS 8.

Here is some log output, checking the top value for textContainerInset , contentInset and scrollIndicatorInset . In each case, after viewDidLoad and keyboardDidShow .

iPhone 5s iOS 7 device :

 2014-09-12 07:55:01.244 Alter[19147:60b] viewDidLoad 2014-09-12 07:55:01.249 Alter[19147:60b] textContainerInset Top: 8.000000 2014-09-12 07:55:01.252 Alter[19147:60b] contentInset Top: 0.000000 2014-09-12 07:55:01.253 Alter[19147:60b] scrollIndicatorInset Top: 0.000000 2014-09-12 07:55:02.515 Alter[19147:60b] keyboardDidShow 2014-09-12 07:55:02.516 Alter[19147:60b] textContainerInset Top: 8.000000 2014-09-12 07:55:02.516 Alter[19147:60b] contentInset Top: 0.000000 2014-09-12 07:55:02.516 Alter[19147:60b] scrollIndicatorInset Top: 0.000000 

Simulator iPhone 5s (or 6 or 6 Plus) with iOS 8 :

 2014-09-12 07:55:39.395 Alter[2120:109535] viewDidLoad 2014-09-12 07:55:39.395 Alter[2120:109535] textContainerInset Top: 8.000000 2014-09-12 07:55:39.396 Alter[2120:109535] contentInset Top: 0.000000 2014-09-12 07:55:39.396 Alter[2120:109535] scrollIndicatorInset Top: 0.000000 2014-09-12 07:55:39.939 Alter[2120:109535] keyboardDidShow 2014-09-12 07:55:39.939 Alter[2120:109535] textContainerInset Top: 8.000000 2014-09-12 07:55:39.939 Alter[2120:109535] contentInset Top: 64.000000 2014-09-12 07:55:39.939 Alter[2120:109535] scrollIndicatorInset Top: 64.000000 

To answer my own question I do not need to manually configure NSTextContainer and NSLayoutManager . Although it would be better to start using the textContainerInset approach, I have the ability to customize the frame if I set it in the parent view controller:

 self.automaticallyAdjustsScrollViewInsets = NO; 
+7
source share

All Articles