我想在我的应用中将模糊的图像作为固定背景。我的ViewController结构是这样的:
HostViewController(带有背景图片和VisualEffectView)
– NavigationController(通过HostViewController形式呈现)
-ViewController(具有清晰的背景色)
当我想从NavigationController推送到另一个ViewController(背景颜色也很清晰)时,新的ViewController与第一个通过新的ViewController可见的ViewController重叠。看起来很奇怪也很丑陋。我的问题是如何在ViewControllers彼此不重叠的情况下实现具有固定背景的推送动画?
您可以在App Store中的“TuneShell”应用程序中看到此效果的示例。
在此先感谢Fabian。
编辑:
为了澄清我的问题,我添加了以下gif:
如在gif中所见,当我按下Playlist-ViewController时,可以在动画时通过新的Playlist-ViewController看到rootViewController。我想解决这个问题。
我想要实现的目标:
最佳答案
我有解决此问题的方法,但是我认为这不是最好的方法,请记住这只是一种解决方法。
首先要做的是将global
背景设置为:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
..
self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blur.jpeg"]];
return YES;
}
blur.jpeg
是我正在使用的清晰(不模糊)图像(例如,从Google获取)接下来是将
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
笔记:
我在 Storyboard 中将
UIViewController
的backgroundColor(ViewController和ViewController2)设置为Default
/none,再次,这只是一种解决方法...这是运行时的示例输出:
希望这会对您有所帮助。
关于ios - 推送具有透明背景的ViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34994027/