Change color behind app on rotation

北战南征 提交于 2019-11-30 17:56:38

问题


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? Changing the UIWindow's background color will not help. Here is an example of the black background in Safari during rotation:


回答1:


I have done something similar but I couldn't find the source now, but here is the idea:

Create and add a significantly larger view as backing view and center it.

Add the UIWebView as subview of this large view whose background is white.

Re-position the center of the UIWebView, too.




回答2:


You can do this way:

Add a UIViewController and set it as initial VC (in screenshot it is MainVC).
Add two UIViewContainer: first for holding your background view , and second for your other vcs.
Override viewDidLayoutSubviews in implementation file of background VC (in this case the .m file of red VC)

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    //Some hardcode :)
    self.view.frame = CGRectMake(-100, -100, 1136, 1136);
}

After doing this you will have something like this:

I know this is not the best solution, but you can do this way until you find the best one.




回答3:


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




回答4:


I got the same issue. As I understand that you want to remove the black background. The easiest solution that I used is set you window clipsToBounds = true instead of your rootViewController.

window?.clipsToBounds = true


来源:https://stackoverflow.com/questions/22427096/change-color-behind-app-on-rotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!