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

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

ios - Why does this iPhone X UIView not get safeAreaLayoutGuide?

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

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...