Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When I replace my window's rootViewController's view it does not give the correct safeAreaLayoutGuide. I'm primarily trying to figure out how to change the following UIView and then get the correct safeAreaLayoutGuide from it.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    UIWindow* uiwindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    UIViewController* vc = [[UIViewController alloc] init];

    vc.view = [[UIView alloc] init];
    uiwindow.rootViewController = vc;
    [uiwindow layoutIfNeeded];
    [uiwindow makeKeyAndVisible];

    UILayoutGuide* guide = [vc.view safeAreaLayoutGuide];
    printf("%f %f %f %f
",[guide layoutFrame].origin.x, [guide layoutFrame].origin.y, [guide layoutFrame].size.width, [guide layoutFrame].size.height);

    [vc.view removeFromSuperview];
    vc.view = [[UIView alloc] init];
    uiwindow.rootViewController = nil;
    uiwindow.rootViewController = vc;
    [uiwindow layoutIfNeeded];

    guide = [vc.view safeAreaLayoutGuide];
    printf("%f %f %f %f
",[guide layoutFrame].origin.x, [guide layoutFrame].origin.y, [guide layoutFrame].size.width, [guide layoutFrame].size.height);

    return YES;
}

Results:

0.000000 44.000000 375.000000 734.000000
0.000000 0.000000 375.000000 812.000000

I'm using SDL and this is the condensed version of it's iOS initialization code. The first/default view is what gets created with a new SDL window. Then the second view gets created when an OpenGL renderer is created. It replaces the first view but then does not give the correct safeAreaLayoutGuide.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
314 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...