0

I have a UITextView with lots of text. The scrolling is mostly smooth on iPhones 4, 5, and 6, but on the 6 Plus there is lots of stuttering. (I believe this is because the 6 Plus is underpowered for the amount of pixels it has to push around). I notice that once I scroll past a region, if I scroll back over it, the scrolling is nice and smooth; layout has already been performed for the region and the processor doesn't have to do much. I want to force layout to occur before I get to the region. This is what I tried:

textView.layoutManager.ensureLayoutForTextContainer(textView.textContainer)

This doesn't appear to do anything at all. The scrolling is still not smooth on first pass over a region, and the before and after log statements have a difference of .00014 of a second. Just to make sure I was really getting the correct text container, I also tried:

textView.layoutManager.ensureLayoutForTextContainer(textView.layoutManager.textContainers[0] as NSTextContainer)

This also made no difference.

What do I need to do to force layout of all text in the text container?

Any help would be greatly appreciated.

Thanks.

EDITED TO ADD: To answer TheCodingArt's question: I'm not doing anything exotic in terms of the layout manager. This is my set up code:

var textStorage = NSTextStorage()
var layoutManager = NSLayoutManager()
textStorage.addLayoutManager(layoutManager)
var textContainer = NSTextContainer(size: textContainerSize)
layoutManager.addTextContainer(textContainer)

textView = UITextView(frame: CGRectMake(0, 0, textViewWidth, textViewHeight), textContainer: textContainer)

textView.showsHorizontalScrollIndicator = false
textView.showsVerticalScrollIndicator = false
textView.backgroundColor = UIColor.clearColor();
textView.editable = false;
textView.selectable = true;
textView.scrollsToTop = false
self.view.addSubview(textView)

Explicity instantiating and adding the text container and text storage is something I learned to do from the first answer to this question: Scroll to bottom of UITextView erratic in iOS 7 ...and which did help somewhat, but not enough for the 6 Plus.

Later, I add text to it:

textStorage.appendAttributedString(attribStr)
Community
  • 1
  • 1
Casey Perkins
  • 1,853
  • 2
  • 23
  • 41
  • I'm not sure what's causing your stuttering issue, but by no means is the 6 Plus underpowered for the amount of pixels it has to push. Go ahead and run bench tests against it and you'll be astonished at how much 'more' power there is versus that of the 6 and 5/5S. There is no crippling factor. It sounds to me like you have constraints that are conflicting in general due to the size of the screen. Also, it's not typical to force constraints to layout using the above. If you're following the lifecycle, you should be fine. – TheCodingArt Feb 16 '15 at 16:39
  • To further assist though, you need to add more context to the equation. I'm assuming that your using a custom layout manager and drawing/detecting text? Otherwise you shouldn't need to touch the layout manager. – TheCodingArt Feb 16 '15 at 16:40
  • Hi, TheCodingArt, thanks for your willingness to help. I added code to the original post to show that I'm not doing anything special for the layout manager. (Also, if you search for iPhone 6 Plus stuttering on Google, you will find plenty of complaints about its performance relative to other models). – Casey Perkins Feb 16 '15 at 16:55
  • Trust me when I say from personal benchmarking and experience, those complaints are in vein lol. I'll take a look over and see what I can deduct. – TheCodingArt Feb 16 '15 at 16:57
  • From what I see above and what I'm thinking, I would love to move this over to an external chat. I would remove all layout manager related and remove/re add the textView and ensure it's layout constraints are correct. I'm going to create a dummy project for you and display a typical text view on an iPhone 6 that scrolls just fine (and I've done this many a times on a 6 Plus). – TheCodingArt Feb 16 '15 at 17:04
  • Here's a dummy project proving that the iPhone 6 Plus and or normally configured textView isn't the culprit: https://bitbucket.org/thegamingart/dummytextview – TheCodingArt Feb 16 '15 at 17:25
  • I'm also providing a sample project in how to properly configure a manual manager in a minute – TheCodingArt Feb 16 '15 at 17:26
  • Thanks again for your help. There are no layout constraints at the moment; I'm positioning everything absolutely. In your dummy project, there would need to be a large amount of text for it to be a rough equivalent. (My text is actually Greek text with frequent instances of color and italic formatting). I am available for external chat but don't know what you have in mind. – Casey Perkins Feb 16 '15 at 17:27
  • Thanks, I will take a look. But do you know how to force layout, and why the ensureLayoutForTextContainer method call mentioned in my original post does nothing? – Casey Perkins Feb 16 '15 at 17:29

0 Answers0