Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding vertical and horizontal notch support for X's iPhones #204

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

rico237
Copy link

@rico237 rico237 commented Mar 28, 2019

Added support for notch safe area insets see those screenshots :

Portrait Landscape
Portrait Landscape

This change is Reviewable

@rudrankriyam
Copy link

It does not support landscape safeAreaLayouts. Can you please add support for it, too? @rico237

@rico237
Copy link
Author

rico237 commented Apr 3, 2019

@snuff4 yeah :) can you paste here a screenshot of the landscaped view ? (note: i don't have a real iphone X so i can only test this on simulator)

@rudrankriyam
Copy link

@rico237 I have a simulator too. :(
In your implementation of landscape mode, it was going into notch, like this -
Screenshot 2019-04-03 at 5 36 01 PM

I solved it using -
'
override func layoutSubviews() {
let size = bounds.size

    let iPhoneX = UIDevice().userInterfaceIdiom == .phone && (UIScreen.main.nativeBounds.height == 2436 || UIScreen.main.nativeBounds.height == 1792 || UIScreen.main.nativeBounds.height == 2688)
    let landscape = UIDevice.current.orientation.isLandscape
    var topSafeAreaHeight: CGFloat = 0.0
    var bottomSafeAreaHeight: CGFloat = 0.0

    if #available(iOS 11.0, *) {
        let window = UIApplication.shared.windows[0]
        let safeFrame = window.safeAreaLayoutGuide.layoutFrame
        topSafeAreaHeight = safeFrame.minY
        bottomSafeAreaHeight = window.frame.maxY - safeFrame.maxY
    }

    previewImageView.frame = bounds
    activityIndicatorView.sizeToFit()
    activityIndicatorView.frame.origin = CGPoint(
        x: (size.width - activityIndicatorView.frame.size.width) / 2,
        y: (size.height - activityIndicatorView.frame.size.height) / 2)
    topBar.sizeToFit()
    topBar.frame = CGRect(
        x: (iPhoneX && landscape) ? 44 : 0,
        y: controlsHidden ? -topBar.frame.size.height : topSafeAreaHeight,
        width: size.width - ((iPhoneX && landscape) ? 88 : 0),
        height: topBar.frame.size.height)
    topBar.alpha = controlsHidden ? 0 : 1
    bottomBar.sizeToFit()
    bottomBar.frame = CGRect(
        x: (iPhoneX && landscape) ? 44 : 0,
        y: size.height - (controlsHidden ? 0 : bottomBar.frame.size.height + bottomSafeAreaHeight),
        width: size.width - ((iPhoneX && landscape) ? 88 : 0),
        height: bottomBar.frame.size.height)
    bottomBar.alpha = controlsHidden ? 0 : 1
    overlayContainerView.frame = CGRect(
        x: 0,
        y: controlsHidden ? 0 : topBar.frame.size.height,
        width: size.width,
        height: size.height - (controlsHidden ? 0 : (topBar.frame.size.height + bottomBar.frame.size.height)))
    for overlay in overlayContainerView.subviews {
        overlay.frame = overlayContainerView.bounds
    }
    super.layoutSubviews()
}

`

Do you have a better approach for it?

@rico237
Copy link
Author

rico237 commented Apr 5, 2019

@snuff4 I will look into a better approach this week-end but i think i would have done the same as you did, if you don't ear from me next monday this means i didn't find any

@rudrankriyam
Copy link

@rico237 Can you update your code, with my approach?

@rico237
Copy link
Author

rico237 commented Apr 8, 2019

@snuff4 I put your fix in my pull request source code ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants