推ViewController与透明背景

我想在我的应用程序中将模糊图像作为固定背景。 我的ViewController结构是这样的:

HostViewController(带背景图像和VisualEffectView)
– NavigationController(通过HostViewController以模态方式呈现)
– ViewController(具有清晰的背景色)

当我想从NavigationController推送到另一个ViewController(它也有明确的背景颜色)时,新的ViewController与第一个ViewController重叠,后者通过新的ViewController可见。 这看起来很奇怪和丑陋。 我的问题是如何在没有ViewControllers相互叠加的情况下实现具有固定背景的推送动画?

您可以在应用程序“TuneShell”中看到此效果的示例,该应用程序可以在App Store中找到。

在此先感谢Fabian。


编辑:为了澄清我的问题,我添加了这个gif:

正如您在gif中看到的那样,当我推送到Playlist-ViewController时,rootViewController在动画时通过新的Playlist-ViewController可见。 我想解决这个问题。

我想要达到的目标:

http://fabian-thies.tk/demo.gif

我有这样的解决方案,但我不认为这是最好的解决方案,请记住,这只是一种解决方法。

首先要做的是设置你的global背景,如:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { .. self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blur.jpeg"]]; return YES; } 

blur.jpeg是一个清晰的(不模糊的)图像我正在使用它(例如从谷歌获取)

在此处输入图像描述

接下来是将UIViewController子类UIViewController全局使用,但是由您决定如何全局实现它。

 //BGBlurViewController.h // @interface BGBlurViewController : UIViewController @end //BGBlurViewController.m // @implementation BGBlurViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UIToolbar *background = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; [background setBarStyle:UIBarStyleBlackTranslucent]; [self.view addSubview:background]; [self.view sendSubviewToBack:background]; } @end 

我正在使用UIToolbar作为UIViewController的背景并实现模糊效果。


这是如何使用子类UIViewController (BGBlurViewController)

 //RootViewController // #import "BGBlurViewController.h" @interface ViewController : BGBlurViewController @end 

另一个:

 //View next to rootViewController // #import "BGBlurViewController.h" @interface ViewController2 : BGBlurViewController @end 

注意:我在故事板中将UIViewController (ViewController和ViewController2)设置为Default / none,这只是一个解决方法……


以下是运行时的示例输出:

在此处输入图像描述

希望这会对你有所帮助..干杯..