Skip to content

Commit

Permalink
Add iPhoneX laypout support
Browse files Browse the repository at this point in the history
Move topview down to the safe area guides and increase bottomview height by the safe area height.
  • Loading branch information
mcahill committed Jan 8, 2018
1 parent ce33e9b commit a4a1ec1
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions Source/Extensions/ConstraintsSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit a4a1ec1

Please sign in to comment.