翻转视图动画不起作用

时间:2011-05-05 18:14:22

标签: iphone ios ipad uiview core-animation

我正在开发一款iPad应用,可在视图中向用户提问。当他们回答问题时,我希望视图转换到包含下一个问题的另一个视图。为了使它看起来很奇特,我试图添加一个curl过渡到它,但我写的代码不起作用,我不能看到找到问题。它确实显示正确的视图,但没有过渡动画。那是什么?这是我用来转换的方法:

- (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;
}

谁能告诉我为什么这不起作用?我非常感谢!

1 个答案:

答案 0 :(得分:0)

为View:_ _self.containerView2的容器设置动画过渡:不是被移除的那个,而是被移除的那个。

相关问题