博客> iOS开发:判断iPhone是否是刘海屏iPhoneX、iPhoneXR、iPhoneXs、iPhoneXs Max等
iOS开发:判断iPhone是否是刘海屏iPhoneX、iPhoneXR、iPhoneXs、iPhoneXs Max等
2019-04-18 15:13 评论:0 阅读:343 yao7778899

Objective-C

// iPhoneX、iPhoneXR、iPhoneXs、iPhoneXs Max等
// 判断刘海屏,返回YES表示是刘海屏
- (BOOL)isNotchScreen {

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        return NO;
    }

    CGSize size = [UIScreen mainScreen].bounds.size;
    NSInteger notchValue = size.width / size.height * 100;

    if (216 == notchValue || 46 == notchValue) {
        return YES;
    }

    return NO;
}

Swift

extension UIViewController {

    /// iPhoneX、iPhoneXR、iPhoneXs、iPhoneXs Max等
    /// 判断刘海屏,返回true表示是刘海屏
    ///
    var isNotchScreen: Bool {

        if UIDevice.current.userInterfaceIdiom == .pad {
            return false
        }

        let size = UIScreen.main.bounds.size
        let notchValue: Int = Int(size.width/size.height * 100)

        if 216 == notchValue || 46 == notchValue {

            return true
        }

        return false
    }
}
收藏
0
sina weixin mail 回到顶部