交换UINavigationController的视图?

时间:2014-06-25 21:47:38

标签: ios iphone objective-c cocoa-touch

我为我的UINavigationController设置了一个背景图片,当我需要它时,我想淡入不同的图像。

我将背景图像设置为:

self.backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BackgroundOne”]];

我试图像这样改变它(我希望它淡入/淡出):

[self.backgroundImageView removeFromSuperview];
self.backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BackgroundTwo”]];
[UIView transitionWithView:self.backgroundImageView duration:0.5f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
    [self.navigationController.view insertSubview:self.backgroundImageView atIndex:0];
} completion:nil];

我没有看到任何变化。想法?

以下工作可以交换背景,但没有褪色动画:

[self.backgroundImageView removeFromSuperview];
self.backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BackgroundTwo"]];
[self.navigationController.view insertSubview:self.backgroundImageView atIndex:0];

1 个答案:

答案 0 :(得分:0)

这个怎么样?


    - (void)switchBackgroundImageViewAnimated:(UIImageView *)newBackgroundImageView
    {
        [self.navigationController.view insertSubview:newBackgroundImageView atIndex:1];
        newBackgroundImageView.alpha = 0.0f;

        [UIView animateWithDuration:0.4f animations:^{
            newBackgroundImageView.alpha = 1.0f;
        } completion:^(BOOL finished) {
            if (finished) {
                [self.backgroundImageView removeFromSuperview];
                self.backgroundImageView = newBackgroundImageView;
            }
        }];
    }