[英]Push ViewController with transparent background
我想在我的應用程序中將模糊圖像作為固定背景。 我的ViewController結構是這樣的:
HostViewController(帶背景圖像和VisualEffectView)
- NavigationController(通過HostViewController以模態方式呈現)
- ViewController(具有清晰的背景色)
當我想從NavigationController推送到另一個ViewController(它也有明確的背景顏色)時,新的ViewController重疊了第一個ViewController,它可以通過新的ViewController看到。 這看起來很奇怪和丑陋。 我的問題是如何在沒有ViewControllers相互疊加的情況下實現具有固定背景的推送動畫?
您可以在應用程序“TuneShell”中看到此效果的示例,該應用程序可以在App Store中找到。
在此先感謝Fabian。
編輯:為了澄清我的問題,我添加了這個gif:
正如你在gif中看到的那樣,當我推送到Playlist-ViewController時,rootViewController在動畫時通過新的Playlist-ViewController可見。 我想解決這個問題。
我想要達到的目標:
我有這樣的解決方案,但我不認為這是最好的解決方案,請記住,這只是一種解決方法。
首先要做的是設置你的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,這只是一個解決方法......
以下是運行時的示例輸出:
希望這會對你有所幫助..干杯..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.