Detect shake gesture IOS Swift

后端 未结 8 2159
难免孤独
难免孤独 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:11

    swift Docs:- https://developer.apple.com/documentation/uikit/uiresponder .

    To detect motion events swift has provided 3 methods:-

    1. func motionBegan() -> Tells the receiver that motion has begun

    2. func motionEnded() -> Tells the receiver that a motion event has ended

    3. func motionCancelled() -> Tells the receiver that a motion event has been cancelled

    For example if you want to update image after shake gesture

    class ViewController: UIViewController {
       override func motionEnded(_ motion: UIEvent.EventSubtype, with event: 
                                                                            UIEvent?) 
       {
            updateImage()
       }
    
       UpdateImage(){
          // Implementation
       }
    }
    

提交回复
热议问题