Resizing NSWindows and NSViews with NSViewAnimation

  • Hello,

      I have an NSWindow with multiple views in it.  In response to a
    user action I (1) resize one view, (2) move some other views, and (3)
    resize the window to snug-fit the result.

      My views are all springed only at the bottom and right to peg them
    to the upper left corner of the window.

      My window resizes fine manually.  (The views stay pegged.)

      When I put my NSViews and my NSWindow in to the same
    NSViewAnimation array, my objects end up all over the place.  If I
    remove the NSWindow from the animation, it works fine.

      I've read the documentation at
    <http://developer.apple.com/documentation/Cocoa/Conceptual/AnimationGuide/Ar
    ticles/ViewAnimations.html
    >

      When I add the NSWindow, I've tried using [window frame] and
    [NSWindow contentRectForFrameRect:[window frame] styleMask:[window
    styleMask]].  Neither work.

      Is there a trick to moving and resizing views while also resizing
    the window?  It's as if the origin is getting messed up as the window
    resizes and the animation is getting confused.

    Thanks,
      Sanford
  • At 10:39 AM -0700 10/18/07, Sanford Selznick wrote:
    > Hello,
    >
    > Is there a trick to moving and resizing views while also resizing
    > the window?  It's as if the origin is getting messed up as the
    > window resizes and the animation is getting confused.

    There is, actually.  ;-)

    First I tried removing all springs from the window's objects.  This
    made all views position properly.  But the animation with
    NSViewAnimation was horrible.

    What I did instead was change the springs and struts at run-time with
    [myView setAutoresizingMask:mask].  Then I changed the frame of the
    window with [window setFrame:newFrame display:YES animate:YES].

    This works really well, and it's many fewer lines than
    NSViewAnimation.  At least when resizing windows is involved.  (I
    guess this only works if the resizing/moving is proportional to the
    window size.)

    I hope this helps somebody.

    Best,
      Sanford
  • I use a similar technique to perform vertical resize animation of
    subviews I've put in a scrollview, and handle width changes when the
    scrollbar appears / disappears. If you use NSViewAnimation, this won't
    work fine because the start and end frames are fixed (I tried changing
    them during the animation but it ended up crashing), so you'd get
    horrible aspect changes during animation.

    To fix that, my NSAnimation delegate performs the frame changes using
    the same dictionary as NSViewAnimation, except that you can change the
    endFrame in the dictionary during the animation. I also play other
    tricks with setAutoresizesSubview: but that's another story...

    Florent

    Sanford Selznick wrote:
    > At 10:39 AM -0700 10/18/07, Sanford Selznick wrote:
    >> Hello,
    >>
    >> Is there a trick to moving and resizing views while also resizing
    >> the window?  It's as if the origin is getting messed up as the window
    >> resizes and the animation is getting confused.
    >
    > There is, actually.  ;-)
    >
    > First I tried removing all springs from the window's objects.  This made
    > all views position properly.  But the animation with NSViewAnimation was
    > horrible.
    >
    > What I did instead was change the springs and struts at run-time with
    > [myView setAutoresizingMask:mask].  Then I changed the frame of the
    > window with [window setFrame:newFrame display:YES animate:YES].
    >
    > This works really well, and it's many fewer lines than NSViewAnimation.
    > At least when resizing windows is involved.  (I guess this only works if
    > the resizing/moving is proportional to the window size.)

    --
    Florent Pillet                        http://www.florentpillet.com
    Software consultant - Mobile devices, desktop and server platforms
    Windows+Mobile, Mac OS X, Palm OS    Skype callto://florent.pillet
previous month october 2007 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 31        
Go to today