feat: two finger swipe to change brightness
This commit was merged in pull request #23.
This commit is contained in:
@@ -50,7 +50,7 @@ struct LocalState: Codable {
|
||||
var backgroundColor: String = "black"
|
||||
}
|
||||
|
||||
class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
let metadataFilename = "metadata.fb"
|
||||
|
||||
var homeView = UIView()
|
||||
@@ -62,6 +62,9 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
|
||||
var pendingAlert: UIAlertController?
|
||||
|
||||
var initialBrightness: CGFloat = 0
|
||||
let dragRangeForFullBrightness: CGFloat = 300
|
||||
|
||||
var imageView = UIImageView()
|
||||
var mode = PageTurnMode.leftToRight
|
||||
var metadataList: [URL: Metadata] = [:]
|
||||
@@ -794,6 +797,11 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
swipeRight.direction = .right
|
||||
readerView.addGestureRecognizer(swipeRight)
|
||||
|
||||
let pan = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:)))
|
||||
pan.minimumNumberOfTouches = 2
|
||||
pan.maximumNumberOfTouches = 2
|
||||
readerView.addGestureRecognizer(pan)
|
||||
|
||||
setupTapZones()
|
||||
}
|
||||
|
||||
@@ -1303,6 +1311,20 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func handlePan(_ gesture: UIPanGestureRecognizer) {
|
||||
switch gesture.state {
|
||||
case .began:
|
||||
initialBrightness = UIScreen.main.brightness
|
||||
case .changed:
|
||||
let translation = gesture.translation(in: view)
|
||||
let delta = -translation.y / dragRangeForFullBrightness
|
||||
let newBrightness = initialBrightness + delta
|
||||
UIScreen.main.brightness = min(max(newBrightness, 0.0), 1.0)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func setupImageView() {
|
||||
imageView.translatesAutoresizingMaskIntoConstraints = false
|
||||
// Scaling is done when the image is loaded to avoid scaling on main thread
|
||||
|
||||
Reference in New Issue
Block a user