xcode 快速向左或向右滑动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37851759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swipe Left or Right in swift
提问by MuaathAli
I have a page that retrieves data from the database to display info about the current info or previous or after
我有一个页面可以从数据库中检索数据以显示有关当前信息或之前或之后的信息
It goes that
是这样的
if Status = 1 it shows the current
Status = 2 it shows previous
Status = 0 it shows next
What I did so far is display the current data and it shows perfectly I need to do a feature that when the user swipes right to left shows next and left to right shows previous
到目前为止我所做的是显示当前数据,它完美地显示我需要做一个功能,当用户从右向左滑动时显示下一个,从左到右显示上一个
Any Idea or guideline just from where to start
从哪里开始的任何想法或指南
Thank you
谢谢
回答by sumeet
override func viewDidLoad()
{
super.viewDidLoad()
let swipeRight = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.view.addGestureRecognizer(swipeRight)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeLeft.direction = UISwipeGestureRecognizerDirection.Left
self.view.addGestureRecognizer(swipeLeft)
}
func respondToSwipeGesture(gesture: UIGestureRecognizer)
{
if let swipeGesture = gesture as? UISwipeGestureRecognizer
{
switch swipeGesture.direction
{
case UISwipeGestureRecognizerDirection.Right:
//write your logic for right swipe
print("Swiped right")
case UISwipeGestureRecognizerDirection.Left:
//write your logic for left swipe
print("Swiped left")
default:
break
}
}
}