stop pause and resume CAAnimation

  • Hi everyone,
    I'm trying to use the animator proxy to modify the size and position of a view, but I want to be able to set the start, end and duration of the animation. I have got this working by using the following code:

    NSDictionary *nsdict = [widget animations];
    CABasicAnimation *originAnim = [CABasicAnimation animationWithKeyPath:@"frameOrigin"];
    CABasicAnimation *sizeAnim = [CABasicAnimation animationWithKeyPath:@"frameSize"];
    [dict setValue:sizeAnim forKey:@"frameSize"];
    [dict setValue:originAnim forKey:@"frameOrigin"];
    originAnim.fromValue= NSValue valueWithPoint:NSMakePoint(300, 300)];
    originAnim.toValue = [NSValue valueWithPoint:NSMakePoint(50, 30)];
    sizeAnim.fromValue= [NSValue valueWithSize:NSMakeSize(100, 30)];
    sizeAnim.toValue = [NSValue valueWithSize:NSMakeSize(350, 30)];
    originAnim.duration = 5.0f;
    sizeAnim.duration = 5.0f;

    NSRect frameRect = NSMakeRect(50, 30, 350, 30);
    [[widget animator] setFrame:frameRect];

    My problem is that I would like to be able to stop, pause and resume the animation before it has finished. I haven't found a way to do this yet. Has anyone solved this problem, or have any suggestions?
    Kevin
    _________________________________________________________________
    Introducing the City @ Live! Take a tour!
    Hi Kevin,

    I've not done this but i would approach it like this;

    1) keep your destination rect around in an ivar or whatever
    2) in the pause: method get the animating view's current position and
    tell the animator to to set that as the new position and remove the
    animations
    3) in the resume: method create a new set of animations and apply them
    and tell the animator setFrame with the destination rect

    You should be able to ignore the 'fromValue' property, it should
    assume the current position if you don't set it.

    HTH,

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

    On Dec 4, 2007, at 9:39 AM, Kevin Barnes wrote:

    >
    > Hi everyone,
    > I'm trying to use the animator proxy to modify the size and position
    > of a view, but I want to be able to set the start, end and duration
    > of the animation. I have got this working by using the following code:
    >
    > NSDictionary *nsdict = [widget animations];
    > CABasicAnimation *originAnim = [CABasicAnimation
    > animationWithKeyPath:@"frameOrigin"];
    > CABasicAnimation *sizeAnim = [CABasicAnimation
    > animationWithKeyPath:@"frameSize"];
    > [dict setValue:sizeAnim forKey:@"frameSize"];
    > [dict setValue:originAnim forKey:@"frameOrigin"];
    > originAnim.fromValue= NSValue valueWithPoint:NSMakePoint(300, 300)];
    > originAnim.toValue = [NSValue valueWithPoint:NSMakePoint(50, 30)];
    > sizeAnim.fromValue= [NSValue valueWithSize:NSMakeSize(100, 30)];
    > sizeAnim.toValue = [NSValue valueWithSize:NSMakeSize(350, 30)];
    > originAnim.duration = 5.0f;
    > sizeAnim.duration = 5.0f;
    >
    > NSRect frameRect = NSMakeRect(50, 30, 350, 30);
    > [[widget animator] setFrame:frameRect];
    >
    >
    > My problem is that I would like to be able to stop, pause and resume
    > the animation before it has finished. I haven't found a way to do
    > this yet. Has anyone solved this problem, or have any suggestions?
    > Kevin
    > _________________________________________________________________
    > Introducing the City @ Live! Take a tour!
    >
    I tried that approach and didn't have much luck with it. Maybe it's worth another go...
    I can't ignore the fromValue as I can't assume that the animation will alway start at the current state.
    -Kevin

    ----------------------------------------
    > From: <bdudney...>
    > To: <cocoa-dev...>
    > Date: Tue, 4 Dec 2007 12:41:56 -0700
    > Subject: Re: stop pause and resume CAAnimation
    >
    > Hi Kevin,
    >
    > I've not done this but i would approach it like this;
    >
    > 1) keep your destination rect around in an ivar or whatever
    > 2) in the pause: method get the animating view's current position and
    > tell the animator to to set that as the new position and remove the
    > animations
    > 3) in the resume: method create a new set of animations and apply them
    > and tell the animator setFrame with the destination rect
    >
    > You should be able to ignore the 'fromValue' property, it should
    > assume the current position if you don't set it.
    >
    > HTH,
    >
    > -bd-
    > http://bill.dudney.net/roller/objc
    >
    > On Dec 4, 2007, at 9:39 AM, Kevin Barnes wrote:
    >
    >>
    >> Hi everyone,
    >> I'm trying to use the animator proxy to modify the size and position
    >> of a view, but I want to be able to set the start, end and duration
    >> of the animation. I have got this working by using the following code:
    >>
    >> NSDictionary *nsdict = [widget animations];
    >> CABasicAnimation *originAnim = [CABasicAnimation
    >> animationWithKeyPath:@"frameOrigin"];
    >> CABasicAnimation *sizeAnim = [CABasicAnimation
    >> animationWithKeyPath:@"frameSize"];
    >> [dict setValue:sizeAnim forKey:@"frameSize"];
    >> [dict setValue:originAnim forKey:@"frameOrigin"];
    >> originAnim.fromValue= NSValue valueWithPoint:NSMakePoint(300, 300)];
    >> originAnim.toValue = [NSValue valueWithPoint:NSMakePoint(50, 30)];
    >> sizeAnim.fromValue= [NSValue valueWithSize:NSMakeSize(100, 30)];
    >> sizeAnim.toValue = [NSValue valueWithSize:NSMakeSize(350, 30)];
    >> originAnim.duration = 5.0f;
    >> sizeAnim.duration = 5.0f;
    >>
    >> NSRect frameRect = NSMakeRect(50, 30, 350, 30);
    >> [[widget animator] setFrame:frameRect];
    >>
    >>
    >> My problem is that I would like to be able to stop, pause and resume
    >> the animation before it has finished. I haven't found a way to do
    >> this yet. Has anyone solved this problem, or have any suggestions?
    >> Kevin
    >> _________________________________________________________________
    >> Introducing the City @ Live! Take a tour!
    >>
previous month december 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