快速向左或向右滑动

时间:2016-06-16 06:47:55

标签: ios xcode swift swipe uiswipegesturerecognizer

我有一个页面,可以从数据库中检索数据,以显示有关当前信息或之前或之后的信息

就是这样

if Status = 1 it shows the current
Status = 2 it shows previous
Status = 0 it shows next

到目前为止,我所做的是显示当前数据并且显示完美 我需要做一个功能,当用户从右向左滑动显示下一个 从左到右显示上一个

任何想法或指南只是从哪里开始

谢谢

1 个答案:

答案 0 :(得分:6)

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
        }
    }
}