Detect shake gesture IOS Swift

后端 未结 8 2144
难免孤独
难免孤独 2020-12-08 02:27

I\'m developing a app with a gesture system, basically if I turn the iPhone to left my app will do a function, if I turn the iPhone to Right, other function, with others ges

8条回答
  •  伪装坚强ぢ
    2020-12-08 03:02

    Swift 5

    class MyViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            self.becomeFirstResponder()
        }
    
        override var canBecomeFirstResponder: Bool {
            get {
                return true
            }
        }
    
        override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
            if motion == .motionShake {
                print("shake")
            }
        }
    
    }
    

提交回复
热议问题