我正试图在窗口中使用UIImageView
发起页面卷曲过渡。这段代码在我的主init方法中:
[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];
图像为位置和大小设置动画,但没有卷曲。如果我取消注释removeFromSuperView
它会立即消失。有什么想法吗?
更新:
更改了代码,因此它使用Lars梦幻般的方式触发动画并包含动画和回调......
[UIView animateWithDuration:1.5
delay:delay
options: UIViewAnimationTransitionCurlUp
animations:^{splashImage.alpha = 0;}
completion:^(BOOL finished){[splashImage removeFromSuperview];}
];
不幸的是页面卷曲不会发生。它虽然消失了。
我不确定这是否与语法有关,或者SplashImage
是我主视图的UIImageView
对象中的UIWindow
类。也许需要在UIView
中创建过渡。
答案 0 :(得分:8)
尝试类似:
[UIView transitionWithView:splashImage
duration:1.5
options: UIViewAnimationOptionTransitionCurlUp
animations^{
splashImage.frame = CGRectMake(-320, 0, 10, 10);
}
completion:^(BOOL finished){
[splashImage removeFromSuperview];
//animCompleteHandlerCode..
}
];
未经测试,可能还有一些语法错误但请试一试!
或者这可能更好:
[UIView animateWithDuration:1.5
delay:delay
options: UIViewAnimationOptionTransitionCurlUp
animations^{
splashImage.frame = CGRectMake(-320, 0, 10, 10);
}
completion:^(BOOL finished){
[splashImage removeFromSuperview];
//animCompleteHandlerCode..
}
];
答案 1 :(得分:1)
@Larsaronen:感谢您的例子,这正是我所需要的!我只想在首次显示图像时想要一个简单的页面卷曲,所以我使用了1.0而不是0的alpha,并将完成回调设置为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];
}