簡體   English   中英

推ViewController與透明背景

[英]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可見。 我想解決這個問題。



我想要達到的目標:

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,這只是一個解決方法......


以下是運行時的示例輸出:

在此輸入圖像描述

希望這會對你有所幫助..干杯..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM