简体   繁体   English

在容器视图(Storyboard)中推入透明背景UIViewController时为灰色背景

[英]Grey color background on pushing transparent background UIViewController inside a Container View (Storyboard)

I'm pushing a UIViewController ( A ) with clearColor as background in a UINavigationController ( N ). 我正在将带有clearColorUIViewControllerA )推入UINavigationControllerN )中作为背景。

N is placed inside a Container View. N放置在容器视图内。 This view has a background that I want to show always. 该视图具有我想始终显示的背景。

容器UINavigation  - 推

Then, when Push is animated it shows a grey/transparent background in my VC ( A ) and when it finishes its animation, it shows correctly. 然后,当对Push进行动画处理时,它会在我的VC( A )中显示灰色/透明背景,当完成动画时,它会正确显示。

Is there any way to avoid this grey color? 有什么办法可以避免这种灰色?

I have 'done' it by putting a white view background in A and making it disappear in viewDidAppear but I think it can be done without that trick... 我已经通过在A中放置白色视图背景并将其在viewDidAppear消失来“完成”,但是我认为可以做到这一点……

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    __weak TestsViewController *weakSelf = self;
    [UIView animateWithDuration:.3 animations:^{
        TestsViewController *ownSelf = weakSelf;
        ownSelf.backgroundView.alpha = 0;
    }];
}

Set your app's window's background colour to white: 将应用程序窗口的背景色设置为白色:

// applicationDidFinishLaunching
self.window.backgroundColor = [UIColor whiteColor];

The push animation often ends up using the background colour of the window behind the transparent areas, and the window background colour is clear by default, so it shows black through the transparent navigation bars and toolbars. 推式动画通常使用透明区域后面的窗口背景色来结束,并且窗口背景色默认情况下是透明的,因此它通过透明导航栏和工具栏显示为黑色。

EDIT : Sorry, misunderstood what the issue was. 编辑 :对不起,误解了问题所在。 When you push a view controller with a transparent background colour, the background you see behind the view controller is the shadow that is rendered behind your view controller (you can see the edge of it when in a non-transparent view controller). 当您推入具有透明背景色的视图控制器时,在该视图控制器后面看到的背景就是在该视图控制器后面渲染的阴影(在非透明视图控制器中,您可以看到其边缘)。

This question has an answer to your issue. 这个问题可以解答您的问题。 Basically, you have to implement a custom animation controller, to provide the transition animation yourself (as described here ). 基本上,你要实现自定义动画控制器,提供自己的过渡动画(如描述在这里 )。 It would probably be easier to continue using your trick than implementing your own custom navigation transition. 继续使用技巧比实现自己的自定义导航过渡要容易得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM