Dynamic NSTextView resizing while keeping Y position constant?

  • I've searched the archives and didn't come up with anything that
    satisfied what I want to do...

    I'm trying to make an NSTextView that automatically resizes itself
    vertically when the user fills it with text to display. But I want it
    to grow in height and not change its Y position. The text view is not
    inside a scroll view.

    If I call -setVerticallyResizable: with YES in the text view, then when
    the text view is filled, it increases its size, but it also decreases
    its Y position in the superview, which makes it look like it's going
    off-screen.

    I've been pointed to the
    -layoutManager:didCompleteLayoutForTextContainer:atEnd: NSLayoutManager
    delegate method, but I'm not sure about what to look for in this
    method. The boolean from the atEnd: is always YES.

    So how can I accomplish this? Does anyone know?

    Nick Zitzmann
    <http://www.chronosnet.com/>
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On 18 Jun 2004, at 20:13, Nick Zitzmann wrote:
    >
    > I'm trying to make an NSTextView that automatically resizes itself
    > vertically when the user fills it with text to display. But I want it
    > to grow in height and not change its Y position. The text view is not
    > inside a scroll view.
    >
    >
    Well, I did it with frame change notifications:
    1. Enable frame change notifications for NSTextView object
    2. Subclass NSTextView to keep old frame (or keep old frame somewhere
    else)
    3. When frame change notification arrives, set the frame origin of
    NSTextView to old origin (set the flag to prevent infinite loop with
    this, because setting the origin will also fire frame change
    notification)

    If somebody has come up with simpler approach, I too would like to
    know...

    Regards,
    izidor
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • If the text view is set to auto-resize itself vertically, then it may
    be that all you really need to do is make sure that its superview is
    flipped...  If the superview is flipped then the frame origin will be
    at the top-left corner of the text view and when the text view resizes
    itself to fit the text, it will naturally grow from the bottom.

    For more sophisticated resizing, you'll need to watch things...  Take a
    look at how TextArea.m in the Sketch example handles this...  It
    watches for textDidChange: notifications as well as using the text
    view's built in horizontally/vertically resizable settings.

    Mike

    Begin forwarded message:

    > From: Izidor Jerebic <izidor.jerebic...>
    > Date: June 19, 2004 9:48:24 AM PDT
    > To: Nick Zitzmann <nick...>
    > Cc: <cocoa-dev...>
    > Subject: Re: Dynamic NSTextView resizing while keeping Y position
    > constant?
    >
    > On 18 Jun 2004, at 20:13, Nick Zitzmann wrote:
    >>
    >> I'm trying to make an NSTextView that automatically resizes itself
    >> vertically when the user fills it with text to display. But I want it
    >> to grow in height and not change its Y position. The text view is not
    >> inside a scroll view.
    >>
    >>
    > Well, I did it with frame change notifications:
    > 1. Enable frame change notifications for NSTextView object
    > 2. Subclass NSTextView to keep old frame (or keep old frame somewhere
    > else)
    > 3. When frame change notification arrives, set the frame origin of
    > NSTextView to old origin (set the flag to prevent infinite loop with
    > this, because setting the origin will also fire frame change
    > notification)
    >
    > If somebody has come up with simpler approach, I too would like to
    > know...
    >
    > Regards,
    > izidor
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Jun 20, 2004, at 12:49 PM, Mike Ferris wrote:

    > If the text view is set to auto-resize itself vertically, then it may
    > be that all you really need to do is make sure that its superview is
    > flipped...  If the superview is flipped then the frame origin will be
    > at the top-left corner of the text view and when the text view resizes
    > itself to fit the text, it will naturally grow from the bottom.

    Thanks Mike! Your solution worked for me.

    Nick Zitzmann
    <http://www.chronosnet.com/>
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month june 2004 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
Go to today
MindNode
MindNode offered a free license !