Flip View Animation Not Working

2019-05-23 21:30发布

问题:

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!

回答1:

Set your animation transition forView: _container of_self.containerView2: not the one that's being removed, but the one it's being removed from.