[英]Push ViewController with transparent background
I want to have a blurred image as a fixed background in my app. 我想在我的应用程序中将模糊图像作为固定背景。 My ViewController structure is like this: 我的ViewController结构是这样的:
HostViewController (with background image and VisualEffectView) HostViewController(带背景图像和VisualEffectView)
– NavigationController (modally presented over the HostViewController) - NavigationController(通过HostViewController以模态方式呈现)
–– ViewController (with clear background color) - ViewController(具有清晰的背景色)
When I want to push to another ViewController (which has also clear background color) from the NavigationController, the new ViewController overlaps the first ViewController which is visible through the new ViewController. 当我想从NavigationController推送到另一个ViewController(它也有明确的背景颜色)时,新的ViewController重叠了第一个ViewController,它可以通过新的ViewController看到。 That looks quite strange and ugly. 这看起来很奇怪和丑陋。 My question is how I could achieve a push animation with a fixed background without the ViewControllers overlaying each other? 我的问题是如何在没有ViewControllers相互叠加的情况下实现具有固定背景的推送动画?
You can see a sample of this effect in the app "TuneShell" which can be found in the App Store. 您可以在应用程序“TuneShell”中看到此效果的示例,该应用程序可以在App Store中找到。
Thanks in advance, Fabian. 在此先感谢Fabian。
EDIT: To clarify my problem I added this gif: 编辑:为了澄清我的问题,我添加了这个gif:
As you can see in the gif, when I push to the Playlist-ViewController, the rootViewController is visible through the new Playlist-ViewController while it's animating. 正如你在gif中看到的那样,当我推送到Playlist-ViewController时,rootViewController在动画时通过新的Playlist-ViewController可见。 I want to fix that. 我想解决这个问题。
WHAT I WANT TO ACHIEVE: 我想要达到的目标:
http://fabian-thies.tk/demo.gif http://fabian-thies.tk/demo.gif
I have a solution for this way back, but I don't think this is the best one and keep in mind that this is just a workaround. 我有这样的解决方案,但我不认为这是最好的解决方案,请记住,这只是一种解决方法。
First thing to do is set your global
background like: 首先要做的是设置你的global
背景,如:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
..
self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blur.jpeg"]];
return YES;
}
blur.jpeg
is a clear(not blurred) image I'm using this for example (got it from google) blur.jpeg
是一个清晰(不模糊)的图像我正在使用它(例如从谷歌获取)
Next is subclassing UIViewController
for global use, but its up to you how to implement it globally. 接下来是将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
I'm using UIToolbar
as a background of UIViewController
and achieve blur effect. 我正在使用UIToolbar
作为UIViewController
的背景并实现模糊效果。
This is how to use the subclassed UIViewController
(BGBlurViewController) 这是如何使用子类UIViewController
(BGBlurViewController)
//RootViewController
//
#import "BGBlurViewController.h"
@interface ViewController : BGBlurViewController
@end
and another: 另一个:
//View next to rootViewController
//
#import "BGBlurViewController.h"
@interface ViewController2 : BGBlurViewController
@end
NOTE: I'm setting the backgroundColor of the UIViewController
s (ViewController and ViewController2) to Default
/none in storyboard, again this is just a workaround... 注意:我在故事板中将UIViewController
(ViewController和ViewController2)设置为Default
/ none,这只是一个解决方法......
Here is the sample output in runtime: 以下是运行时的示例输出:
Hope this would help you.. Cheers.. 希望这会对你有所帮助..干杯..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.