views:

158

answers:

1

I'm trying to instigate a page curl transition with a UIImageView in a Window. This code is in my main init method :

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationDelay:delay];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDidStopSelector:@selector(animCompleteHandler:finished:context:)];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:splashImage cache:YES];

splashImage.frame = CGRectMake(-320, 0, 10, 10);
//[splashImage removeFromSuperview];

[UIView commitAnimations];

The image animates position and size but no curl. If I uncomment the removeFromSuperView it just vanishes instantly. Any ideas?

UPDATE:

Have changed the code so it uses Lars fantasticlly neat way of triggering an animation and including the animation and callback ...

[UIView animateWithDuration:1.5
                      delay:delay
                    options: UIViewAnimationTransitionCurlUp 
                 animations:^{splashImage.alpha = 0;}
                 completion:^(BOOL finished){[splashImage removeFromSuperview];}
 ];

Unfortunately the page curl just doesn't happen. It does fade though.

I'm not sure if this is something to do with the syntax or the fact that the SplashImage is a UIImageView class in the UIWindow object of my main view. Maybe it needs to be in a UIView to create the transition.

+1  A: 

Try something like:

[UIView transitionWithView:splashImage 
        duration:1.5 
        options: UIViewAnimationOptionTransitionCurlUp 
        animations^{
            splashImage.frame = CGRectMake(-320, 0, 10, 10);
        } 
        completion:^(BOOL finished){
            [splashImage removeFromSuperview];
            //animCompleteHandlerCode..
        }
];

Not tested and maybe some syntax errors but give it a try!

Or maybe this is better:

[UIView animateWithDuration:1.5
        delay:delay
        options: UIViewAnimationOptionTransitionCurlUp 
        animations^{
            splashImage.frame = CGRectMake(-320, 0, 10, 10);
        } 
        completion:^(BOOL finished){
            [splashImage removeFromSuperview];
             //animCompleteHandlerCode..
        }
];
Larsaronen
I've not tried this yet but I'm intrigued by your code! What does the ^ do? Is this a way of embedding functions?
Lee Probert
Those are blocks new to iOS 4.0.I encourage you to read up on blocks. Great addition to iOS. Check out this: http://developer.apple.com/library/ios/#featuredarticles/Short_Practical_Guide_Blocks/index.htmlIf i understand your code correctly what you want to do is curl a page and at the same time move and scale it?
Larsaronen
well the moving and scaling is not really important ... I just wanted to trigger the transition. Was using that transformation just to test it was working. I just need the splash image to page curl away. To trigger this as a transition I need to do something to the view. Would it work with 'hidden'? Anyway, I'm running some tests now. Thanks for your feedback.
Lee Probert
Yeah probably.. Just pass in nil instead of the animation block.. And set the splashImage to hidden or alpha to 0.0.. After or before the transition method..
Larsaronen