Have you tried just setting the textContentInset to make room for your subview?

I used that approach a couple of days ago to add room for a subview at the 
bottom of a UITextView and it worked like a charm. Worth a shot here too.

Thanks,
Jon


> On Apr 1, 2015, at 2:19 PM, Seth Willits <[email protected]> wrote:
> 
> I have a text view where I added a subview at the top, and I want all of the 
> text to be below this subview. You can think of it like having a horizontal 
> ruler above the text view, but instead I want this view (it's not a ruler) 
> _in_ the text view so that it scrolls with the text.
> 
> Here are two different strategies, neither of which I can quite get to work...
> 
> 
> 
> --
> 
> The simplest thing I could think of was to subclass NSTextView and override 
> textContainerOrigin to push the Y value down a little. My little accessory 
> view then becomes a direct subview of the text view. The first line of text 
> is exactly in the right spot so it seems like it'll work perfectly, but if 
> the text fills the entire text view, it won't start scrolling until the 
> height of the *text* is greater than the height of the entire text *view*, 
> which means that however many points I've shifted the text down by, that many 
> points of text is cut off at the bottom of the text view before scrolling is 
> allowed.
> 
> In other words, if the text view's could hold 10 lines of text, I shift all 
> the text down by 1 line, and put 10 lines of text into the text view, I 
> expect to see 9 lines and have to scroll to see the 10th, but instead, the 
> scrollview doesn't allow scrolling at all, so that 10th line is completely 
> inaccessible. If I add an 11th line, then I can scroll to the 10th line, but 
> not the 11th, etc.
> 
> 
> So whatever mechanism is calculating how much scrolling is needed, doesn't 
> respect the text container's origin as returned by NSTextView 
> -textContainerOrigin? I can't seem to figure out how to "fix" that.
> 
> 
> ---
> 
> 
> A completely different approach would be to affect typesetting where the line 
> fragments "flow" around this view, by just making sure the line fragments 
> don't start until below it. I implemented this strategy with a custom text 
> container, and it appears to work at first, but if the text is long enough 
> that scrolling is required, then the first line fragment is just at 0,0 in 
> the text container regardless of the fact that I explicitly told it to not 
> be...
> 
> 
> @implementation MyTextContainer
> 
> - (BOOL)isSimpleRectangularTextContainer
> {
>       return NO;
> }
> 
> - (NSRect)lineFragmentRectForProposedRect:(NSRect)proposedRect 
> sweepDirection:(NSLineSweepDirection)sweepDirection 
> movementDirection:(NSLineMovementDirection)movementDirection 
> remainingRect:(NSRectPointer)remainingRect
> {
>       if (proposedRect.origin.y + proposedRect.size.height > 
> self.containerSize.height) {
>               return [super lineFragmentRectForProposedRect:proposedRect 
> sweepDirection:sweepDirection movementDirection:movementDirection 
> remainingRect:remainingRect];
>       }
>       
>       
>       if (!NSIntersectsRect(NSMakeRect(0, 0, self.containerSize.width, 26), 
> proposedRect)) {
>               return [super lineFragmentRectForProposedRect:proposedRect 
> sweepDirection:sweepDirection movementDirection:movementDirection 
> remainingRect:remainingRect];
>       }
>       
>       
>       NSRect reproposedRect;
>       reproposedRect.origin.x = proposedRect.origin.x;
>       reproposedRect.size.height = proposedRect.size.height;
>       reproposedRect.size.width = self.containerSize.width;
>       reproposedRect.origin.y = 26;
>       reproposedRect = [self lineFragmentRectForProposedRect:reproposedRect 
> sweepDirection:sweepDirection movementDirection:movementDirection 
> remainingRect:remainingRect];
>       return reproposedRect;
> }
> 
> 
> @end
> 
> 
> 
> 
> So there are two different strategies, and I've hit a sizable enough wall 
> that with both that I'm kinda stumped. 
> 
> Anyone had any luck doing something like this?
> 
> 
> 
> --
> Seth Willits
> 
> 
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list ([email protected])
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/jhull%40gbis.com
> 
> This email sent to [email protected]


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to