翻转视图动画不起作用

发布于 2024-11-05 04:53:40 字数 1504 浏览 1 评论 0原文

我正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞琼窗梦回ˉ 2024-11-12 04:53:40

设置动画过渡 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文