I am quite new to programming and Objective C. I was wondering how to make an app which has a blank screen and a timer that goes for one minute. You are meant to tap as fast
Works in Xcode 11.4, Swift 5
class ViewController: UIViewController {
@IBOutlet weak var targetView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let tap = UITapGestureRecognizer(target: self, action: #selector(self.touchCallback(_:)))
self.targetView.addGestureRecognizer(tap)
}
@objc func touchCallback(_ sender: UITapGestureRecognizer? = nil) {
if(sender?.state == .ended) {
print("tapped")
}
}
}
// If you want to touch start, available touchesBegan
class ViewController: UIViewController {
@IBOutlet weak var targetView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func touchesBegan(_ touches: Set, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: targetView)
print(location)
}
}
}