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

Missing grid view #50

Open
mnfro opened this issue Aug 11, 2020 · 1 comment
Open

Missing grid view #50

mnfro opened this issue Aug 11, 2020 · 1 comment

Comments

@mnfro
Copy link

mnfro commented Aug 11, 2020

Hi @eonist , great job with this repo, it looks pretty neat. Apart from the possibility to add filters, one thing which is also missing is a grid view. I can't issue a PR right now, but here is the code:

class GridView: UIView {
    
    @objc public var color: UIColor = UIColor.white.withAlphaComponent(0.5) {
        didSet {
            self.setNeedsDisplay()
        }
    }
    
    @objc public override init(frame: CGRect) {
        super.init(frame: frame)
        self.setupView()
    }
    
    @objc public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.setupView()
    }
    
    private func setupView() {
        self.backgroundColor = UIColor.clear
    }
    
    private override func draw(_ rect: CGRect) {
        super.draw(rect)
        
        guard let context = UIGraphicsGetCurrentContext() else {
            return
        }
        
        context.setStrokeColor(self.color.cgColor)
        context.setLineWidth(1.0)
        
        let pairs: [[CGPoint]] = [
            [CGPoint(x: rect.width / 3.0, y: rect.minY), CGPoint(x: rect.width / 3.0, y: rect.maxY)],
            [CGPoint(x: 2 * rect.width / 3.0, y: rect.minY), CGPoint(x: 2 * rect.width / 3.0, y: rect.maxY)],
            [CGPoint(x: rect.minX, y: rect.height / 3.0), CGPoint(x: rect.maxX, y: rect.height / 3.0)],
            [CGPoint(x: rect.minX, y: 2 * rect.height / 3.0), CGPoint(x: rect.maxX, y: 2 * rect.height / 3.0)]
        ]
        
        for pair in pairs {
            context.addLines(between: pair)
        }
        
        context.strokePath()
    }
}

It is a rule-of-third grid, the most common we can find in any camera app.

If added to the camera view as a subview should not interfere with any gesture recognizer. What's more, a simple UIButton can be used to hide or show the grid.

Cheers!

p.s I'm a master of crooked photos.

@eonist
Copy link
Owner

eonist commented Aug 11, 2020

Awesome!

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

No branches or pull requests

2 participants