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

Fix iPhone X / XS Bug #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions UIImageCropper/UIImageCropper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,9 @@ public class UIImageCropper: UIViewController, UIImagePickerControllerDelegate,
bottomView.backgroundColor = UIColor.black.withAlphaComponent(0.7)
self.view.addSubview(topView)
self.view.addSubview(bottomView)
topView.translatesAutoresizingMaskIntoConstraints = false
bottomView.translatesAutoresizingMaskIntoConstraints = false
let horizontalTopConst = NSLayoutConstraint.constraints(withVisualFormat: "H:|-(0)-[view]-(0)-|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: ["view": topView])
let horizontalBottomConst = NSLayoutConstraint.constraints(withVisualFormat: "H:|-(0)-[view]-(0)-|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: ["view": bottomView])
let verticalConst = NSLayoutConstraint.constraints(withVisualFormat: "V:|-(0)-[top]-(0)-[bottom(70)]-|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: ["bottom": bottomView, "top": topView])
self.view.addConstraints(horizontalTopConst + horizontalBottomConst + verticalConst)
view.addConstraintsWithFormat(format: "H:|[v0]|", views: topView)
view.addConstraintsWithFormat(format: "H:|[v0]|", views: bottomView)
view.addConstraintsWithFormat(format: "V:|[v0][v1(70)]|", views: topView, bottomView)

// image view
imageView.contentMode = .scaleAspectFit
Expand Down Expand Up @@ -148,9 +145,9 @@ public class UIImageCropper: UIViewController, UIImagePickerControllerDelegate,
topView.addSubview(cropView)
let centerXConst = NSLayoutConstraint(item: cropView, attribute: .centerX, relatedBy: .equal, toItem: topView, attribute: .centerX, multiplier: 1, constant: 0)
let centerYConst = NSLayoutConstraint(item: cropView, attribute: .centerY, relatedBy: .equal, toItem: topView, attribute: .centerY, multiplier: 1, constant: 0)
let widthConst = NSLayoutConstraint(item: cropView, attribute: .width, relatedBy: .equal, toItem: topView, attribute: .width, multiplier: 0.9, constant: 0)
let widthConst = NSLayoutConstraint(item: cropView, attribute: .width, relatedBy: .equal, toItem: topView, attribute: .width, multiplier: 1, constant: -20)
widthConst.priority = .defaultHigh
let heightConst = NSLayoutConstraint(item: cropView, attribute: .height, relatedBy: .lessThanOrEqual, toItem: topView, attribute: .height, multiplier: 0.9, constant: 0)
let heightConst = NSLayoutConstraint(item: cropView, attribute: .height, relatedBy: .lessThanOrEqual, toItem: topView, attribute: .height, multiplier: 1, constant: -20)
let ratioConst = NSLayoutConstraint(item: cropView, attribute: .width, relatedBy: .equal, toItem: cropView, attribute: .height, multiplier: cropRatio, constant: 0)
cropView.addConstraints([ratioConst])
topView.addConstraints([widthConst, heightConst, centerXConst, centerYConst])
Expand Down