overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() var swipeRight = UISwipeGestureRecognizer(target: self,action: "respondToSwipeGesture:") swipeRight.direction = UISwipeGestureRecognizerDirection.Right self.vIEw.addGestureRecognizer(swipeRight) var swipeDown = UISwipeGestureRecognizer(target: self,action: "respondToSwipeGesture:") swipeDown.direction = UISwipeGestureRecognizerDirection.Down self.vIEw.addGestureRecognizer(swipeDown)}func respondToSwipeGesture(gesture: UIGestureRecognizer) { if let swipeGesture = gesture as? UISwipeGestureRecognizer { switch swipeGesture.direction { case UISwipeGestureRecognizerDirection.Right: print("Swiped right") case UISwipeGestureRecognizerDirection.Down: print("Swiped down") case UISwipeGestureRecognizerDirection.left: print("Swiped left") case UISwipeGestureRecognizerDirection.Up: print("Swiped up") default: break } }}
Swift 3:
overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() let swipeRight = UISwipeGestureRecognizer(target: self,action: #selector(self.respondToSwipeGesture)) swipeRight.direction = UISwipeGestureRecognizerDirection.right self.vIEw.addGestureRecognizer(swipeRight) let swipeDown = UISwipeGestureRecognizer(target: self,action: #selector(self.respondToSwipeGesture)) swipeDown.direction = UISwipeGestureRecognizerDirection.down self.vIEw.addGestureRecognizer(swipeDown)}func respondToSwipeGesture(gesture: UIGestureRecognizer) { if let swipeGesture = gesture as? UISwipeGestureRecognizer { switch swipeGesture.direction { case UISwipeGestureRecognizerDirection.right: print("Swiped right") case UISwipeGestureRecognizerDirection.down: print("Swiped down") case UISwipeGestureRecognizerDirection.left: print("Swiped left") case UISwipeGestureRecognizerDirection.up: print("Swiped up") default: break } }}总结
以上是内存溢出为你收集整理的swift – 如何识别所有4个方向的滑动全部内容,希望文章能够帮你解决swift – 如何识别所有4个方向的滑动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)