gpt4 book ai didi

ios - 推送透明背景的ViewController

转载 作者:可可西里 更新时间:2023-11-01 04:24:54 25 4
gpt4 key购买 nike

我想在我的应用程序中使用模糊图像作为固定背景。我的 ViewController 结构是这样的:

HostViewController(带背景图片和VisualEffectView)
– NavigationController(通过 HostViewController 模态呈现)
–– ViewController(背景色清晰)

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

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

提前致谢,法比安。



编辑:为了澄清我的问题,我添加了这个 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 是一个清晰(不模糊)的图像,例如我正在使用它(从谷歌获取)

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

我正在使用 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(ViewController 和 ViewController2)的 backgroundColor 设置为 Default/none,同样这只是一种解决方法...


这是运行时的示例输出:

enter image description here

希望这对你有帮助..干杯..

关于ios - 推送透明背景的ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34994027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com