small medium large xlarge

08fb87e_pragsmall
06 Mar 2009, 16:41
Tom H (8 posts)

I’m utterly confounded trying to use a context: set up my UIView animation.

I’d like to use the context to tell the delegate for the animation did stop selector how long the next animation should last. Given that context is a pointer to anything (void *), I should be able to pass an NSNumber or any object, correct?

Things get dicey in the delegate animation did stop selector. I cast the context to the type that I know that it should be (NSNumber) and then attempt to get a float value out of it – but no go.

What am I missing? I’m certain that I’m completely mis-remembering something about pointers but have really run into a brick wall . . .

-(void) doSomeAnimationForDuration:(float) seconds {

NSNumber *duration = [NSNumber numberWithFloat:seconds * 0.5f];
[UIView beginAnimations:@"foo" context:duration];
[UIView setAnimationDuration:seconds/2.0f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(someAnimationDidStop:finished:context:)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// change some property values here  
[UIView commitAnimations];
}

</code>

the delegate method . . .

-(void) someAnimationDidStop:(NSString *)animationID finished:(BOOL)finished context:(void *)duration {
	
NSNumber *seconds = (NSNumber *)duration;  // removing the cast d/n work either . . . 

// why can't I pull the float value out?
float f = [seconds floatValue]; // this is where we crash . . . 

[UIView beginAnimations:@"foo2" context:nil];
[UIView setAnimationDuration: [seconds floatValue]];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(glowOffAnimationDidStop)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//change another set of properties here
[UIView commitAnimations];
}

</code>

08fb87e_pragsmall
12 Mar 2009, 21:18
Tom H (8 posts)

FWIW, retaining the NSNumber solves the problem . . .

but don’t forget to release it later . . .

You must be logged in to comment