Flip View Animation Not Working

血红的双手。 提交于 2019-12-22 18:36:24

问题


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.



来源:https://stackoverflow.com/questions/5902316/flip-view-animation-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!