iOS-Lernen – Höhe der Navigationsleiste und Statusleiste ermitteln

Ermitteln Sie die Höhe der Statusleiste der Navigationsleiste: 


- (float)getStatusBarAndNavigationBarHeight{
    UIWindowScene *windowScene = (UIWindowScene *)[UIApplication sharedApplication].connectedScenes.allObjects.firstObject;
    UIStatusBarManager *statusBarManager = windowScene.statusBarManager;
    CGFloat statusBarHeight = statusBarManager.statusBarFrame.size.height;
    CGFloat navigationBarHeight = self.navigationController.navigationBar.frame.size.height;
    return statusBarHeight + navigationBarHeight;
}

Es kann auch mit einem Makro geschrieben werden:

#define kStatusBarHeight ((UIWindowScene *)[UIApplication sharedApplication].connectedScenes.allObjects.firstObject).statusBarManager.statusBarFrame.size.height

おすすめ

転載: blog.csdn.net/qq_43441647/article/details/131597856
おすすめ