2

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

- (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,好像动画部分被跳过了,但是块被执行了?

如果我在其中切换容器,[UIView transitionWithView:containerself.view会翻转整个视图(正如怀疑的那样),但我无法使用self.view.

有没有办法解决这个问题?

我正在寻找类似 iPad Photos应用程序的东西,其中图片将翻转并缩放到全屏。

我真的希望有人可以在这里帮助我,提前谢谢你。

4

1 回答 1

-3

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

这应该有效。

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

                }];

如果没有,请考虑创建视图实例变量并确保在尝试为它们设置动画之前分配它们。如果您想在按钮按下时进行动画处理,您也可以直接使用 sender 执行此操作,前提是整个视图是 UIButton。

我希望它有所帮助。

于 2011-01-24T12:21:57.763 回答