comparison ios/dw.m @ 2570:2c2941e01b67

iOS: Slight refactoring to handle the possibility that the status bar changes size.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 20 May 2021 10:22:20 +0000
parents 97b30df25fd1
children 6fdab466d7a2
comparison
equal deleted inserted replaced
2569:97b30df25fd1 2570:2c2941e01b67
1425 DWWindow *window = (DWWindow *)[[self view] window]; 1425 DWWindow *window = (DWWindow *)[[self view] window];
1426 NSArray *array = [window subviews]; 1426 NSArray *array = [window subviews];
1427 CGRect frame = [window frame]; 1427 CGRect frame = [window frame];
1428 DWView *view = nil; 1428 DWView *view = nil;
1429 UINavigationBar *nav = nil; 1429 UINavigationBar *nav = nil;
1430 NSInteger sbheight = 0; 1430 NSInteger sbheight = [[[window windowScene] statusBarManager] statusBarFrame].size.height;
1431 1431
1432 for(id obj in array) 1432 for(id obj in array)
1433 { 1433 {
1434 if([obj isMemberOfClass:[DWView class]]) 1434 if([obj isMemberOfClass:[DWView class]])
1435 view = obj; 1435 view = obj;
1436 else if([obj isMemberOfClass:[UINavigationBar class]]) 1436 else if([obj isMemberOfClass:[UINavigationBar class]])
1445 /* Adjust the frame to account for the status bar and navigation bar if it exists */ 1445 /* Adjust the frame to account for the status bar and navigation bar if it exists */
1446 if(nav) 1446 if(nav)
1447 { 1447 {
1448 CGRect navrect = [nav frame]; 1448 CGRect navrect = [nav frame];
1449 1449
1450 sbheight = navrect.size.height;
1451 navrect.size.width = frame.size.width; 1450 navrect.size.width = frame.size.width;
1451 navrect.origin.x = 0;
1452 navrect.origin.y = sbheight;
1453 sbheight += navrect.size.height;
1452 [nav setFrame:navrect]; 1454 [nav setFrame:navrect];
1453 1455
1454 if (@available(iOS 14.0, *)) { 1456 if (@available(iOS 14.0, *)) {
1455 DWMenu *windowmenu = [window menu]; 1457 DWMenu *windowmenu = [window menu];
1456 UINavigationItem *item = [[nav items] firstObject]; 1458 UINavigationItem *item = [[nav items] firstObject];
1463 } 1465 }
1464 } else { 1466 } else {
1465 // Fallback on earlier versions 1467 // Fallback on earlier versions
1466 } 1468 }
1467 } 1469 }
1468 else
1469 sbheight = [[[window windowScene] statusBarManager] statusBarFrame].size.height;
1470 frame.size.height -= sbheight; 1470 frame.size.height -= sbheight;
1471 /* Account for the special area on iPhone X and iPad Pro 1471 /* Account for the special area on iPhone X and iPad Pro
1472 * https://blog.maxrudberg.com/post/165590234593/ui-design-for-iphone-x-bottom-elements 1472 * https://blog.maxrudberg.com/post/165590234593/ui-design-for-iphone-x-bottom-elements
1473 */ 1473 */
1474 frame.size.height -= 24; 1474 frame.size.height -= 24;
8013 if(@available(iOS 13.0, *)) { 8013 if(@available(iOS 13.0, *)) {
8014 NSString *nstitle = [NSString stringWithUTF8String:title]; 8014 NSString *nstitle = [NSString stringWithUTF8String:title];
8015 [window setLargeContentTitle:nstitle]; 8015 [window setLargeContentTitle:nstitle];
8016 if(flStyle & DW_FCF_TITLEBAR) 8016 if(flStyle & DW_FCF_TITLEBAR)
8017 { 8017 {
8018 UINavigationBar* navbar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, screenrect.size.width, 60)]; 8018 NSInteger sbheight = [[[window windowScene] statusBarManager] statusBarFrame].size.height;
8019 UINavigationBar* navbar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, sbheight, screenrect.size.width, 40)];
8019 UINavigationItem* navItem = [[UINavigationItem alloc] initWithTitle:nstitle]; 8020 UINavigationItem* navItem = [[UINavigationItem alloc] initWithTitle:nstitle];
8020 8021
8021 [navbar setItems:@[navItem]]; 8022 [navbar setItems:@[navItem]];
8022 [window addSubview:navbar]; 8023 [window addSubview:navbar];
8023 } 8024 }