将两个视图添加为 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。等等。