是否不可能使用“transitionWithView”翻转 viewControllers.view 的子视图?使用块

发布于 2024-10-12 05:38:01 字数 1334 浏览 8 评论 0原文

我根本无法让它发挥作用,我认为这很简单,但没有运气。

- (void) animate {

    UIView *viewA = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 100.0f)];
    [viewA setBackgroundColor:[UIColor blueColor]];
    UIView *viewB = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 100.0f)];
    [viewB setBackgroundColor:[UIColor brownColor]];

    UIView *container = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 300.0f, 100.0f)];
    [container addSubview:viewA];

    [self.view addSubview:container];

    [UIView transitionWithView:container
                      duration:0.4
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    animations:^{
                        [[[container subviews] objectAtIndex:0] removeFromSuperview];
                        [container addSubview:viewB];
                    }
                    completion:^(BOOL finished){

                    }];


}

文档建议您这样做,创建一个容器,添加/删除要在其之间翻转的两个子视图。

我无法让它工作。它只会显示viewA,然后显示viewB,就好像跳过了动画部分,但是执行了块?

如果我使用 self.view 切换 [UIViewtransitionWithView:container 中的容器,它会翻转整个视图(如怀疑的那样),但我无法让它用 2 来执行此操作self.view 的子视图。

难道就没有办法解决这个问题吗?

我正在寻找类似 iPad 照片 应用程序的功能,其中图片将翻转并缩放至全屏。

我真的希望有人能帮助我,提前谢谢你。

I simply can't get this to work, I would think it was simple, but no luck.

- (void) animate {

    UIView *viewA = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 100.0f)];
    [viewA setBackgroundColor:[UIColor blueColor]];
    UIView *viewB = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 100.0f)];
    [viewB setBackgroundColor:[UIColor brownColor]];

    UIView *container = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 300.0f, 100.0f)];
    [container addSubview:viewA];

    [self.view addSubview:container];

    [UIView transitionWithView:container
                      duration:0.4
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    animations:^{
                        [[[container subviews] objectAtIndex:0] removeFromSuperview];
                        [container addSubview:viewB];
                    }
                    completion:^(BOOL finished){

                    }];


}

This is how the documentation recommends you do it, make a container, add/remove the two subviews you want to flip between.

I can't get it to work. It will just display viewA, then viewB, as if the animation part is skipped, but the block is carried out?

If I switch the container in the [UIView transitionWithView:container with self.view it flips the entire view (As suspected) but I can not get it to do this with 2 subviews of self.view.

Is there no way around this?

I am looking to do something like the iPad Photos app, where a picture will flip and scale to full screen.

I really hope someone could help me out here, thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

錯遇了你 2024-10-19 05:38:01

您不能在块内放置分号。如果您想在其中完成两件事,请用“,”将它们分开。
如果你想要的话,CurveEase 可能也不错。

这应该有效。

[UIView transitionWithView:container
                  duration:0.4
                   options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionCurveEaseInOut
                animations:^{
                    [[[container subviews] objectAtIndex:0] removeFromSuperview],
                    [container addSubview:viewB];
                }
                completion:^(BOOL finished){

                }];

如果没有,请考虑创建视图实例变量并确保在尝试对它们进行动画处理之前已分配它们。如果你想在按钮按下时制作动画,如果整个视图是一个 UIButton,你也可以直接使用 sender 来完成。

我希望它有帮助。

You can't put semicolons inside the block. If you want two things done in there, divide them with a ",".
Also CurveEase would probably be nice., if you want it.

This should work.

[UIView transitionWithView:container
                  duration:0.4
                   options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionCurveEaseInOut
                animations:^{
                    [[[container subviews] objectAtIndex:0] removeFromSuperview],
                    [container addSubview:viewB];
                }
                completion:^(BOOL finished){

                }];

If it does not, consider making the views instance variables and make sure they're allocated before you try to animate them. If you want to animate on a button push, you can do it directly with sender too, if the whole view is a UIButton.

I hope it helps.

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