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)