From a4a1ec1ab049698650aa0e8c34fe8a6bfbd2a8eb Mon Sep 17 00:00:00 2001 From: mcahill Date: Mon, 8 Jan 2018 14:52:47 -0800 Subject: [PATCH] Add iPhoneX laypout support Move topview down to the safe area guides and increase bottomview height by the safe area height. --- Source/Extensions/ConstraintsSetup.swift | 31 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Source/Extensions/ConstraintsSetup.swift b/Source/Extensions/ConstraintsSetup.swift index 4a0841c7..5b296afb 100644 --- a/Source/Extensions/ConstraintsSetup.swift +++ b/Source/Extensions/ConstraintsSetup.swift @@ -103,7 +103,7 @@ extension ImagePickerController { func setupConstraints() { let attributes: [NSLayoutAttribute] = [.bottom, .right, .width] - let topViewAttributes: [NSLayoutAttribute] = [.left, .top, .width] + let topViewAttributes: [NSLayoutAttribute] = [.left, .width] for attribute in attributes { view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: attribute, @@ -123,9 +123,32 @@ extension ImagePickerController { multiplier: 1, constant: 0)) } - view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: .height, - relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, - multiplier: 1, constant: BottomContainerView.Dimensions.height)) + if #available(iOS 11.0, *) { + view.addConstraint(NSLayoutConstraint(item: topView, attribute: .top, + relatedBy: .equal, toItem: view.safeAreaLayoutGuide, + attribute: .top, + multiplier: 1, constant: 0)) + } else { + view.addConstraint(NSLayoutConstraint(item: topView, attribute: .top, + relatedBy: .equal, toItem: view, + attribute: .top, + multiplier: 1, constant: 0)) + } + + if #available(iOS 11.0, *) { + let heightPadding = UIApplication.shared.keyWindow!.safeAreaInsets.bottom + view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: .height, + relatedBy: .equal, toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: BottomContainerView.Dimensions.height + heightPadding)) + } else { + view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: .height, + relatedBy: .equal, toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: BottomContainerView.Dimensions.height)) + } view.addConstraint(NSLayoutConstraint(item: topView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute,