I'm trying to implement custom pagination such as 'keep with next paragraph' or 'keep lines on same page'. But after reading Apple docs and googling I still don't have a clue how to do that.
I guess that the main point of interest is the delegate method of the NSLayoutManagerDelegate (layoutManager( didCompleteLayoutFor textContainer)). And in that method it's easy to calculate whether the paragraph did layout inside the text container or it didn't fit.
But what to do next? How can I tell the layout manager to re-layout that paragraph on the next page?
I've discovered a way to do the job. In the NSLayoutManagerDelegate method didCompleteLayoutFor textContainer: I'm checking if some paragraph lies in more that one text container and if so, just reduce height of the first one. Works like a charm, but requires relayout of the text.