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

Fix iPhone X / XS Bug #11

wants to merge 1 commit into from

Conversation

unixb0y
Copy link

@unixb0y unixb0y commented Aug 11, 2019

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.

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:

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))
    }
}
@jvk75
Copy link
Owner

jvk75 commented Aug 25, 2019

This fixes the crop frame when coming form camera but messes up frame even more when selecting from gallery. Need to study some more.

@unixb0y
Copy link
Author

unixb0y commented Aug 29, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants