Skip to content

Commit a4a1ec1

Browse files
author
mcahill
committed
Add iPhoneX laypout support
Move topview down to the safe area guides and increase bottomview height by the safe area height.
1 parent ce33e9b commit a4a1ec1

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

Source/Extensions/ConstraintsSetup.swift

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ extension ImagePickerController {
103103

104104
func setupConstraints() {
105105
let attributes: [NSLayoutAttribute] = [.bottom, .right, .width]
106-
let topViewAttributes: [NSLayoutAttribute] = [.left, .top, .width]
106+
let topViewAttributes: [NSLayoutAttribute] = [.left, .width]
107107

108108
for attribute in attributes {
109109
view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: attribute,
@@ -123,9 +123,32 @@ extension ImagePickerController {
123123
multiplier: 1, constant: 0))
124124
}
125125

126-
view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: .height,
127-
relatedBy: .equal, toItem: nil, attribute: .notAnAttribute,
128-
multiplier: 1, constant: BottomContainerView.Dimensions.height))
126+
if #available(iOS 11.0, *) {
127+
view.addConstraint(NSLayoutConstraint(item: topView, attribute: .top,
128+
relatedBy: .equal, toItem: view.safeAreaLayoutGuide,
129+
attribute: .top,
130+
multiplier: 1, constant: 0))
131+
} else {
132+
view.addConstraint(NSLayoutConstraint(item: topView, attribute: .top,
133+
relatedBy: .equal, toItem: view,
134+
attribute: .top,
135+
multiplier: 1, constant: 0))
136+
}
137+
138+
if #available(iOS 11.0, *) {
139+
let heightPadding = UIApplication.shared.keyWindow!.safeAreaInsets.bottom
140+
view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: .height,
141+
relatedBy: .equal, toItem: nil,
142+
attribute: .notAnAttribute,
143+
multiplier: 1,
144+
constant: BottomContainerView.Dimensions.height + heightPadding))
145+
} else {
146+
view.addConstraint(NSLayoutConstraint(item: bottomContainer, attribute: .height,
147+
relatedBy: .equal, toItem: nil,
148+
attribute: .notAnAttribute,
149+
multiplier: 1,
150+
constant: BottomContainerView.Dimensions.height))
151+
}
129152

130153
view.addConstraint(NSLayoutConstraint(item: topView, attribute: .height,
131154
relatedBy: .equal, toItem: nil, attribute: .notAnAttribute,

0 commit comments

Comments
 (0)