Choppy Core Animation

  • Fellow list members..

    I have been round and round with my choppy resize animation.
    Basically I have a custom view in IB that contains 3 subviews. I am
    trying the iTunes "show/hide" artwork effect. Basically I have a
    NSTableView that is wrapped in a custom nsview that displays financial
    transactions and the view underneath displays a detailed view of the
    selected transaction.  To trigger the resize, the user just double-
    clicks the transaction and I resize both custom nsviews. shrinking the
    deatil view  down and expanding the transaction view so that the
    transaction nstableview takes up any remaining space. I am guessing
    that I am redrawing excessively which might be causing the
    "choppiness". I am open to any and all suggestions.  I have pasted the
    relevant code below.

    Thanks,
    Hasani

    Utilities.m -----------------------------------------------------------

    /**
      * Sets the frame for a view with animation.
      */
    +(void)setFrameForViewWithAnimation:(NSView *)view frame:(NSRect)frame
    {

    if ( [ view wantsLayer ] )
    {
      [ [ view animator ] setFrame:frame ];
    }
    else
    {
      NSRect startFrame = [ view frame ];

      // create the dictionary..
      NSMutableDictionary *animationDictionary = [ [ NSMutableDictionary
    alloc ] init ];

      // set the target
      [ animationDictionary setObject:view
    forKey:NSViewAnimationTargetKey ];

      // set the starting size..
      [ animationDictionary setObject:[ NSValue valueWithRect:startFrame ]
    forKey:NSViewAnimationStartFrameKey ];

      // set the end frame
      [ animationDictionary setObject:[ NSValue valueWithRect:frame ]
    forKey:NSViewAnimationEndFrameKey ];

      // construct the animation..
      NSViewAnimation *animation = [ [ NSViewAnimation alloc ]
    initWithViewAnimations:[ NSArray
    arrayWithObject:animationDictionary ] ];

      // set the duration of the animation..
      [ animation setDuration:0.25 ];

      [ animation startAnimation ];

      [ animation release ];
    }

    }
  • OK, one comment off the top.

    I see no Core Animation in this example. This is strictly
    NSViewAnimation or Animatable proxies.

    Which part doesn't work?

    is it when you have layer backing turned on? or off?

    what does your drawing method look like?

    On Nov 1, 2007, at 7:14 PM, Hasani Hunter wrote:

    > Fellow list members..
    >
    > I have been round and round with my choppy resize animation.
    > Basically I have a custom view in IB that contains 3 subviews. I am
    > trying the iTunes "show/hide" artwork effect. Basically I have a
    > NSTableView that is wrapped in a custom nsview that displays
    > financial transactions and the view underneath displays a detailed
    > view of the selected transaction.  To trigger the resize, the user
    > just double-clicks the transaction and I resize both custom nsviews.
    > shrinking the deatil view  down and expanding the transaction view
    > so that the transaction nstableview takes up any remaining space. I
    > am guessing that I am redrawing excessively which might be causing
    > the "choppiness". I am open to any and all suggestions.  I have
    > pasted the relevant code below.
    >
    > Thanks,
    > Hasani
    >
    > Utilities.m
    > -----------------------------------------------------------
    >
    > /**
    > * Sets the frame for a view with animation.
    > */
    > +(void)setFrameForViewWithAnimation:(NSView *)view frame:(NSRect)frame
    > {
    >
    > if ( [ view wantsLayer ] )
    > {
    > [ [ view animator ] setFrame:frame ];
    > }
    > else
    > {
    > NSRect startFrame = [ view frame ];
    >
    > // create the dictionary..
    > NSMutableDictionary *animationDictionary = [ [ NSMutableDictionary
    > alloc ] init ];
    >
    > // set the target
    > [ animationDictionary setObject:view
    > forKey:NSViewAnimationTargetKey ];
    >
    > // set the starting size..
    > [ animationDictionary setObject:[ NSValue
    > valueWithRect:startFrame ] forKey:NSViewAnimationStartFrameKey ];
    >
    > // set the end frame
    > [ animationDictionary setObject:[ NSValue valueWithRect:frame ]
    > forKey:NSViewAnimationEndFrameKey ];
    >
    > // construct the animation..
    > NSViewAnimation *animation = [ [ NSViewAnimation alloc ]
    > initWithViewAnimations:[ NSArray
    > arrayWithObject:animationDictionary ] ];
    >
    > // set the duration of the animation..
    > [ animation setDuration:0.25 ];
    >
    > [ animation startAnimation ];
    >
    > [ animation release ];
    > }
    >
    > }
  • I added the following code:

    CALayer *viewLayer = [ view layer ];

    // create a keyframe animation..
    CAKeyframeAnimation *keyAnimation = [ CAKeyframeAnimation animation ];

    // set the keypath
    [ keyAnimation setKeyPath:@"frame" ];

    // create an array of values..
    NSArray *animationArray = [ NSArray arrayWithObjects:
        [ NSValue valueWithRect:[ view frame ] ],
        [ NSValue valueWithRect:frame ],nil ];

    [ keyAnimation setValues:animationArray ];

    [ viewLayer addAnimation:keyAnimation forKey:@"frame" ];

    [ [ view animator ] setFrame:frame ];

    I'm still not convinced that this is right, but the animation is a bit
    smoother..

    On Nov 2, 2007, at 5:05 AM, Scott Anguish wrote:

    > OK, one comment off the top.
    >
    > I see no Core Animation in this example. This is strictly
    > NSViewAnimation or Animatable proxies.
    >
    > Which part doesn't work?
    >
    > is it when you have layer backing turned on? or off?
    >
    > what does your drawing method look like?
    >
    >
    >
    > On Nov 1, 2007, at 7:14 PM, Hasani Hunter wrote:
    >
    >> Fellow list members..
    >>
    >> I have been round and round with my choppy resize animation.
    >> Basically I have a custom view in IB that contains 3 subviews. I am
    >> trying the iTunes "show/hide" artwork effect. Basically I have a
    >> NSTableView that is wrapped in a custom nsview that displays
    >> financial transactions and the view underneath displays a detailed
    >> view of the selected transaction.  To trigger the resize, the user
    >> just double-clicks the transaction and I resize both custom
    >> nsviews. shrinking the deatil view  down and expanding the
    >> transaction view so that the transaction nstableview takes up any
    >> remaining space. I am guessing that I am redrawing excessively
    >> which might be causing the "choppiness". I am open to any and all
    >> suggestions.  I have pasted the relevant code below.
    >>
    >> Thanks,
    >> Hasani
    >>
    >> Utilities.m
    >> -----------------------------------------------------------
    >>
    >> /**
    >> * Sets the frame for a view with animation.
    >> */
    >> +(void)setFrameForViewWithAnimation:(NSView *)view frame:
    >> (NSRect)frame
    >> {
    >>
    >> if ( [ view wantsLayer ] )
    >> {
    >> [ [ view animator ] setFrame:frame ];
    >> }
    >> else
    >> {
    >> NSRect startFrame = [ view frame ];
    >>
    >> // create the dictionary..
    >> NSMutableDictionary *animationDictionary =
    >> [ [ NSMutableDictionary alloc ] init ];
    >>
    >> // set the target
    >> [ animationDictionary setObject:view
    >> forKey:NSViewAnimationTargetKey ];
    >>
    >> // set the starting size..
    >> [ animationDictionary setObject:[ NSValue
    >> valueWithRect:startFrame ] forKey:NSViewAnimationStartFrameKey ];
    >>
    >> // set the end frame
    >> [ animationDictionary setObject:[ NSValue valueWithRect:frame ]
    >> forKey:NSViewAnimationEndFrameKey ];
    >>
    >> // construct the animation..
    >> NSViewAnimation *animation = [ [ NSViewAnimation alloc ]
    >> initWithViewAnimations:[ NSArray
    >> arrayWithObject:animationDictionary ] ];
    >>
    >> // set the duration of the animation..
    >> [ animation setDuration:0.25 ];
    >>
    >> [ animation startAnimation ];
    >>
    >> [ animation release ];
    >> }
    >>
    >> }
    >
  • Hi,

    You don't need to mess with the animation stuff at all if all you want
    to do is make a subview animate the change of its frame.

    I've got an example on my blog at

    http://bill.dudney.net/roller/objc/entry/4

    Basically just ask the animator proxy to set the frame and it will
    animate.

    i.e.

    drop the if/else and just use the

    >>> [ [ view animator ] setFrame:frame ];
    >>

    line.

    HTH,

    -bd-
    http://bill.dudney.net/roller/objc

    On Nov 2, 2007, at 7:34 PM, Hasani Hunter wrote:

    > I added the following code:
    >
    > CALayer *viewLayer = [ view layer ];
    >
    > // create a keyframe animation..
    > CAKeyframeAnimation *keyAnimation = [ CAKeyframeAnimation animation ];
    >
    > // set the keypath
    > [ keyAnimation setKeyPath:@"frame" ];
    >
    > // create an array of values..
    > NSArray *animationArray = [ NSArray arrayWithObjects:
    > [ NSValue valueWithRect:[ view frame ] ],
    > [ NSValue valueWithRect:frame ],nil ];
    >
    > [ keyAnimation setValues:animationArray ];
    >
    > [ viewLayer addAnimation:keyAnimation forKey:@"frame" ];
    >
    > [ [ view animator ] setFrame:frame ];
    >
    > I'm still not convinced that this is right, but the animation is a
    > bit smoother..
    >
    > On Nov 2, 2007, at 5:05 AM, Scott Anguish wrote:
    >
    >> OK, one comment off the top.
    >>
    >> I see no Core Animation in this example. This is strictly
    >> NSViewAnimation or Animatable proxies.
    >>
    >> Which part doesn't work?
    >>
    >> is it when you have layer backing turned on? or off?
    >>
    >> what does your drawing method look like?
    >>
    >>
    >>
    >> On Nov 1, 2007, at 7:14 PM, Hasani Hunter wrote:
    >>
    >>> Fellow list members..
    >>>
    >>> I have been round and round with my choppy resize animation.
    >>> Basically I have a custom view in IB that contains 3 subviews. I
    >>> am trying the iTunes "show/hide" artwork effect. Basically I have
    >>> a NSTableView that is wrapped in a custom nsview that displays
    >>> financial transactions and the view underneath displays a detailed
    >>> view of the selected transaction.  To trigger the resize, the user
    >>> just double-clicks the transaction and I resize both custom
    >>> nsviews. shrinking the deatil view  down and expanding the
    >>> transaction view so that the transaction nstableview takes up any
    >>> remaining space. I am guessing that I am redrawing excessively
    >>> which might be causing the "choppiness". I am open to any and all
    >>> suggestions.  I have pasted the relevant code below.
    >>>
    >>> Thanks,
    >>> Hasani
    >>>
    >>> Utilities.m
    >>> -----------------------------------------------------------
    >>>
    >>> /**
    >>> * Sets the frame for a view with animation.
    >>> */
    >>> +(void)setFrameForViewWithAnimation:(NSView *)view frame:
    >>> (NSRect)frame
    >>> {
    >>>
    >>> if ( [ view wantsLayer ] )
    >>> {
    >>> [ [ view animator ] setFrame:frame ];
    >>> }
    >>> else
    >>> {
    >>> NSRect startFrame = [ view frame ];
    >>>
    >>> // create the dictionary..
    >>> NSMutableDictionary *animationDictionary =
    >>> [ [ NSMutableDictionary alloc ] init ];
    >>>
    >>> // set the target
    >>> [ animationDictionary setObject:view
    >>> forKey:NSViewAnimationTargetKey ];
    >>>
    >>> // set the starting size..
    >>> [ animationDictionary setObject:[ NSValue
    >>> valueWithRect:startFrame ] forKey:NSViewAnimationStartFrameKey ];
    >>>
    >>> // set the end frame
    >>> [ animationDictionary setObject:[ NSValue valueWithRect:frame ]
    >>> forKey:NSViewAnimationEndFrameKey ];
    >>>
    >>> // construct the animation..
    >>> NSViewAnimation *animation = [ [ NSViewAnimation alloc ]
    >>> initWithViewAnimations:[ NSArray
    >>> arrayWithObject:animationDictionary ] ];
    >>>
    >>> // set the duration of the animation..
    >>> [ animation setDuration:0.25 ];
    >>>
    >>> [ animation startAnimation ];
    >>>
    >>> [ animation release ];
    >>> }
    >>>
    >>> }
    >>

  • this is entirely unnecessary.

    simply using the frame method should work through the animator proxy.

    On Nov 2, 2007, at 9:34 PM, Hasani Hunter wrote:

    > I added the following code:
    >
    > CALayer *viewLayer = [ view layer ];
    >
    > // create a keyframe animation..
    > CAKeyframeAnimation *keyAnimation = [ CAKeyframeAnimation animation ];
    >
    > // set the keypath
    > [ keyAnimation setKeyPath:@"frame" ];
    >
    > // create an array of values..
    > NSArray *animationArray = [ NSArray arrayWithObjects:
    > [ NSValue valueWithRect:[ view frame ] ],
    > [ NSValue valueWithRect:frame ],nil ];
    >
    > [ keyAnimation setValues:animationArray ];
    >
    > [ viewLayer addAnimation:keyAnimation forKey:@"frame" ];
    >
    > [ [ view animator ] setFrame:frame ];
    >
    > I'm still not convinced that this is right, but the animation is a
    > bit smoother..
    >
    > On Nov 2, 2007, at 5:05 AM, Scott Anguish wrote:
    >
    >> OK, one comment off the top.
previous month november 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    
Go to today