This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@objc func twoFingersGestureRecognizer(sender: TwoFingersGestureRecognizer) { | |
if sender.state == .ended { | |
if sender.fingersDirection == .moveDown && !self.settings.isDarkMode { | |
self.settings?.isDarkMode = true | |
self.settingsHandler.save(settings: self.settings) | |
player.play(name: "switch-on") | |
NotificationCenter.default.post(name: .darkModeEnabled, object: nil) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let twoFingersGestureReognizer = TwoFingersGestureRecognizer(target: self, action: #selector(twoFingersGestureRecognizer)) | |
twoFingersGestureReognizer.cancelsTouchesInView = false | |
twoFingersGestureReognizer.delegate = self | |
self.view.addGestureRecognizer(twoFingersGestureReognizer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func reset() { | |
super.reset() | |
self.fingersDirection = TwoFingersMove.unknown | |
self.firstTouchedPoints.removeAll(keepingCapacity: true) | |
self.secondTouchedPoints.removeAll(keepingCapacity: true) | |
state = .possible | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func twoFingersMoveUp() -> Bool { | |
var firstFingerWasMoveUp = false | |
if firstTouchedPoints.count > 1 && firstTouchedPoints[0].y > firstTouchedPoints[firstTouchedPoints.count - 1].y { | |
firstFingerWasMoveUp = true | |
} | |
var secondFingerWasMoveUp = false | |
if secondTouchedPoints.count > 1 && secondTouchedPoints[0].y > secondTouchedPoints[secondTouchedPoints.count - 1].y { | |
secondFingerWasMoveUp = true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) { | |
super.touchesEnded(touches, with: event) | |
if self.twoFingersMoveUp() { | |
self.fingersDirection = TwoFingersMove.moveUp | |
state = .ended | |
return | |
} | |
if self.twoFingersMoveDown() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) { | |
super.touchesMoved(touches, with: event) | |
if state == .failed || touches.count != 2 { | |
return | |
} | |
let window = view?.window | |
let arrayTouches = Array(touches) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) { | |
super.touchesBegan(touches, with: event) | |
if touches.count >= 1 { | |
state = .began | |
return | |
} | |
state = .failed | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
class BaseViewController: UIViewController { | |
var settingsHandler = SettingsHandler() | |
var settings:Settings! | |
// MARK: - View loading | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
class BaseTableViewController : UITableViewController { | |
var settingsHandler = SettingsHandler() | |
var settings:Settings! | |
// MARK: - View loading | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func toggleDarkModeSwitch(_ sender: UISwitch) { | |
self.settings?.isDarkMode = sender.isOn | |
self.settingsHandler.save(settings: self.settings) | |
NotificationCenter.default.post(name: sender.isOn ? .darkModeEnabled : .darkModeDisabled, object: nil) | |
} |