翻转视图动画不起作用
我正在开发一个 iPad 应用程序,它在视图中向用户提出问题。当他们回答问题时,我希望视图转换到包含下一个问题的另一个视图。为了使它看起来很奇特,我试图向它添加一个卷曲过渡,但我编写的代码不起作用,我看不到找到问题。它确实显示了正确的视图,但没有过渡动画。这是怎么回事?这是我用来转换的方法:
- (void)pageChangedTo:(NSInteger)page {
if ( (page == currentQuestionNumber) || (page > ( [self.allQuestions count] - 1 ) ) || (page < 0) ) {
return;
}
AskQuestionView *view = [self.questionViews objectAtIndex:page];
UIViewAnimationTransition transition;
if (page > currentQuestionNumber) {
transition = UIViewAnimationTransitionCurlUp;
}
else {
transition = UIViewAnimationTransitionCurlDown;
}
if (self.containerView1.superview) {
self.containerView2 = view;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:transition forView:self.containerView1 cache:YES];
[self.containerView1 removeFromSuperview];
[askQuestionsView addSubview:self.containerView2];
[UIView commitAnimations];
}
else {
self.containerView1 = view;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:transition forView:self.containerView2 cache:YES];
[self.containerView2 removeFromSuperview];
[askQuestionsView addSubview:self.containerView1];
[UIView commitAnimations];
}
currentQuestionNumber = page;
}
谁能告诉我为什么这不起作用?我将非常感激!
I am working on an iPad app that presents a question to the user in a view. When they answer the question, I would like the view to transition to another view that contains the next question. To make it look all fancy, I am trying to add a curl transition to it but the code I wrote does not work can I can't see to find the problem. It does show the correct view but there is no transition animation. What's with that? Here is the method I use to transition:
- (void)pageChangedTo:(NSInteger)page {
if ( (page == currentQuestionNumber) || (page > ( [self.allQuestions count] - 1 ) ) || (page < 0) ) {
return;
}
AskQuestionView *view = [self.questionViews objectAtIndex:page];
UIViewAnimationTransition transition;
if (page > currentQuestionNumber) {
transition = UIViewAnimationTransitionCurlUp;
}
else {
transition = UIViewAnimationTransitionCurlDown;
}
if (self.containerView1.superview) {
self.containerView2 = view;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:transition forView:self.containerView1 cache:YES];
[self.containerView1 removeFromSuperview];
[askQuestionsView addSubview:self.containerView2];
[UIView commitAnimations];
}
else {
self.containerView1 = view;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:transition forView:self.containerView2 cache:YES];
[self.containerView2 removeFromSuperview];
[askQuestionsView addSubview:self.containerView1];
[UIView commitAnimations];
}
currentQuestionNumber = page;
}
Can anyone tell me why this isn't working? I would very much appreciate it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置动画过渡 forView: _容器_self.containerView2:不是要删除的容器,而是从中删除的容器。
Set your animation transition forView: _container of_self.containerView2: not the one that's being removed, but the one it's being removed from.