Advertisement
RybaSG

ThirdVC

Jun 2nd, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.16 KB | None | 0 0
  1. import UIKit
  2.  
  3. class ThirdViewController: UIViewController {
  4.  
  5.     @IBOutlet weak var secondsValue: UILabel!
  6.     var timer = Timer()
  7.     var activeTimer = false
  8.     var counter = 0
  9.     var Single_Tap : UITapGestureRecognizer!
  10.     var D_Tap : UITapGestureRecognizer!
  11.     var Swipe_Right : UISwipeGestureRecognizer!
  12.    
  13.     @objc func count()
  14.     {
  15.     counter += 1
  16.     secondsValue.text = String(counter)
  17.     }
  18.    
  19.     @objc func handleSwipes()
  20.     {
  21.         counter = 0
  22.         secondsValue.text = String(counter)
  23.     }
  24.    
  25.     @objc func handleSingleTap()
  26.     {
  27.         if(!activeTimer){
  28.         timer = Timer.scheduledTimer(timeInterval:1,target:self, selector: #selector(count),userInfo:nil,repeats:true)
  29.             activeTimer = true
  30.         }
  31.     }
  32.    
  33.     @objc func handleDTap(){
  34.         timer.invalidate()
  35.         activeTimer = false
  36.     }
  37.    
  38.     override func viewDidLoad() {
  39.         super.viewDidLoad()
  40.        
  41.        
  42.         Swipe_Right = UISwipeGestureRecognizer(target:
  43.             self, action: #selector(handleSwipes))
  44.        
  45.         Single_Tap = UITapGestureRecognizer(target:
  46.         self, action: #selector(handleSingleTap))
  47.        
  48.         D_Tap = UITapGestureRecognizer(target:
  49.             self, action: #selector(handleDTap))
  50.        
  51.         D_Tap.numberOfTouchesRequired = 2
  52.        
  53.         Single_Tap.numberOfTouchesRequired = 1
  54.         Swipe_Right.direction = .right
  55.         view.addGestureRecognizer(Swipe_Right)
  56.         view.addGestureRecognizer(Single_Tap)
  57.         view.addGestureRecognizer(D_Tap)
  58.         // Do any additional setup after loading the view.
  59.     }
  60.  
  61.     override func didReceiveMemoryWarning() {
  62.         super.didReceiveMemoryWarning()
  63.         // Dispose of any resources that can be recreated.
  64.     }
  65.    
  66.  
  67.     /*
  68.     // MARK: - Navigation
  69.  
  70.     // In a storyboard-based application, you will often want to do a little preparation before navigation
  71.     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  72.         // Get the new view controller using segue.destinationViewController.
  73.         // Pass the selected object to the new view controller.
  74.     }
  75.     */
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement