UIImageCropper
UIImageCropper copied to clipboard
Fix iPhone X / XS Bug
On the iPhone X / XS, the cropView and fadeView were not perfectly on top of each other (offset in y direction) and in addition, the Crop / Retake buttons weren't pinned to the bottom of the screen. This is fixed by the first couple lines.
I also set the height / width constants not to be proportional to the screen size but fixed since that's what I generally prefer for this situation.
You'll need the following extension for the first few lines to work: (it's generally a very helpful one)
extension UIView {
func addConstraintsWithFormat(format: String, views: UIView...) {
var viewDict = [String: AnyObject]()
for (index, view) in views.enumerated() {
view.translatesAutoresizingMaskIntoConstraints = false
let key = "v\(index)"
viewDict[key] = view
}
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: format, options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: viewDict))
}
}
Alternatively, you could use something like this in lines 106-108 (and don't have to use the extension):
topView.translatesAutoresizingMaskIntoConstraints = false
bottomView.translatesAutoresizingMaskIntoConstraints = false
[topView.leftAnchor.constraint(equalTo: view.leftAnchor),
topView.rightAnchor.constraint(equalTo: view.rightAnchor),
bottomView.leftAnchor.constraint(equalTo: view.leftAnchor),
bottomView.rightAnchor.constraint(equalTo: view.rightAnchor),
topView.topAnchor.constraint(equalTo: view.topAnchor),
bottomView.topAnchor.constraint(equalTo: topView.bottomAnchor),
bottomView.heightAnchor.constraint(equalToConstant: 70),
bottomView.bottomAnchor.constraint(equalTo: view.bottomAnchor)].forEach({ $0.isActive = true })
It will also fix the iPhone X / XS bug.
This fixes the crop frame when coming form camera but messes up frame even more when selecting from gallery. Need to study some more.
This fixes the crop frame when coming form camera but messes up frame even more when selecting from gallery. Need to study some more.
TBH, I use it for selecting from gallery. It should be mentioned that I create my layout in code and use AutoLayout. Maybe that's why we get different results?
If I remember, I can quickly create a mini App tomorrow to show that it works in that case :D