0

我想构建一个只有 1 个屏幕的相当简单的应用程序。因此,我想在同一个视图控制器中有两个视图。

View1 - appear for 5 seconds
View2 - appear during gameplay
View1 - appear for 5 seconds
View2 - appear during gameplay
And so on. 

虽然我不知道如何实现这一点,但我确信这种设计模式是有效的。

我搜索了文档,但找不到明确的答案。

我知道执行此操作的应用程序,但如何,我不知道。

是 viewcontroller.view = View1 还是 View2?如果是这样,我将如何使用一些漂亮的动画进行此切换?

我知道动画,但在这种情况下不知道。请帮忙...

4

1 回答 1

1

将两个视图添加为 viewController 视图的子视图:

[viewController.view addSubview:view1];
[viewController.view addSubview:view2];

然后使用动画块:

// the following code will replace view1 with view2 after a 5 second delay

// this ensures view2 is behind view1
[viewController.view bringSubviewToFront:view2];
[viewController.view bringSubviewToFront:view1];

// get view2 ready for the animation
view2.alpha = 0;
view2.hidden = NO;

// delay for 5 seconds before executing animation
[UIView animateWithDuration:duration delay:5 options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction) animations:^{

    //fade out
    view1.alpha = 0;

    // fade in
    view2.alpha = 1;

} completion:^(BOOL finished) {

    // hide it after animation completes
    view1.hidden = YES;

    // bring view2 to front (even though view1 is not visible, it is still above view2)
    [viewController.view bringSubviewToFront:view2];
}];

用 view2 替换 view1。等等。

于 2012-12-18T20:09:13.980 回答