iPhone page curl transition animation
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.
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: Thanks for the examples, it was exactly what I needed! I just wanted a simple page curl while images are first displayed, so I used an alpha of 1.0 instead of 0, and set the completion callback to nil:
// set a page curl animation for the specified UIImageView control
- (void) setAnimationPageCurl:(UIImageView *)imageView {
[UIView transitionWithView:imageView
duration:1.5
options:UIViewAnimationOptionTransitionCurlDown
animations:^ { imageView.alpha = 1.0; }
completion:nil];
}
精彩评论