HybridCamera
HybridCamera copied to clipboard
Missing grid view
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.
Awesome!
- I would suggest making it a module. Similar to when we added: https://github.com/eonist/ZoomSwitcherKit and add it via SPM
- This way people can cherry pick which components they want to include etc