2016-01-25 35 views
3

我想在我的应用程序中将图像模糊为固定背景。我的视图控制器结构是这样的:推送透明背景的ViewController

HostViewController(与背景图像和VisualEffectView)
- NavigationController(模态呈现在HostViewController)
- 视图控制器(有明确的背景色)

当我要推从NavigationController到另一个ViewController(它也有清晰的背景色),新的ViewController重叠了第一个ViewController,它通过新的ViewController可见。这看起来很奇怪和丑陋。我的问题是,如何在没有ViewController的情况下实现具有固定背景的推动画?

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

在此先感谢,Fabian。



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

正如你可以在GIF看,当我推到Playlist- ViewController,当它是动画时,rootViewController通过新的Playlist-ViewController可见。我想解决这个问题。



什么,我想实现:

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

+0

您必须添加背景在AppDelegate.m窗口在-didFinishLaunching里面。 – 0yeoj

+0

@ 0yeoj谢谢你,但那不是我真正的问题。我编辑了我的问题,以便您更好地理解我的问题。 – FTFT1234

+0

啊..我看到..你有没有尝试在'-viewWillDisappear'里面设置'self.view.alpha = 0'? – 0yeoj

回答

6

我有这样回的解决方案,但我不认为这是最好的一个,并保持记住这只是一个解决方法。

第一件事要做的就是设置你的global背景,如:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    .. 
    self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blur.jpeg"]]; 

    return YES; 
} 

blur.jpeg是我使用这个例如(得到它从谷歌)清晰(不模糊)图像

enter image description here

接下来是子类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 

我使用UIToolbarUIViewController背景,达到虚化效果。


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

//RootViewController 
// 
#import "BGBlurViewController.h" 

@interface ViewController : BGBlurViewController 

@end 

和另:

//View next to rootViewController 
// 
#import "BGBlurViewController.h" 

@interface ViewController2 : BGBlurViewController 

@end 

注: 我设置UIViewController S的的backgroundColor(视图控制器和ViewController2)到Default /无故事板,这也只是一种解决方法...


这是在运行时的输出样本:

enter image description here

希望这会帮助你..干杯..

+0

非常感谢你,这工作非常好! :) – FTFT1234

+0

@ FTFT1234;别客气。 :) – 0yeoj

+0

@ FTFT1234相当聪明的把戏:)你知道幕后发生了什么吗?为什么它只适用于UIToolbar?你有没有找到一个“解决方法 - 解决方案”:)? – ospr