A block of code to distinguish the full-screen iPhone

Use a static variable

If you just want to do simple processing depending on different iPhone models, recommend the following static variable:

static var isFullScreen: Bool {
    if #available(iOS 11, *) {
        guard let w = UIApplication.shared.delegate?.window, let unwrapedWindow = w else {
            return false
        }
            
        if unwrapedWindow.safeAreaInsets.left > 0 || unwrapedWindow.safeAreaInsets.bottom > 0 {
            //print(unwrapedWindow.safeAreaInsets)
            return true
        }
    }
    return false
}

Install ScreenType by Cocoapods

ScreenType is a library to easily distinguish between iPhone models in Objective-C and Swift. And you could install it by Cocoapods.

Go to GitHub – allgamesallfree/ScreenType: Easily distinguish between iph models in Objective-C and Swift or Easily distinguish between iph models – maxste.in in order to find further explanations.

Advertisements

分类:iOS

Tagged as: , ,

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.