Change color behind app on rotation

后端 未结 4 1545
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 04:54

When an iOS app rotates it will reveal a black background when the app is between portrait and landscape. Is it possible to change this color from the default black to white

4条回答
  •  爱一瞬间的悲伤
    2021-01-06 05:31

    You can solve the problem by adding empty general view controller with oversized bounds into your root viewController and make it the lowest in the view hierarchy:

    CGFloat length = 2*MAX(rootViewController.view.bounds.size.height, rootViewController.view.bounds.size.width);
    
    UIView *oversizedBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, length, length)];
    oversizedBackgroundView.center = vc.view.center;
    oversizedBackgroundView.backgroundColor = [UIColor whiteColor];
    rootViewController.view.clipsToBounds = NO;
    [rootViewController.view addSubview:oversizedBackgroundView];
    [rootViewController.view sendSubviewToBack:oversizedBackgroundView];
    
    self.window.rootViewController = rootViewController;
    [self.window makeKeyAndVisible];
    

    The key point here is to set clipsToBounds to NO

提交回复
热议问题