【问题标题】:Swipe Left or Right in swift快速向左或向右滑动
【发布时间】:2016-10-24 19:01:37
【问题描述】:

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

原来如此

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

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

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

谢谢

【问题讨论】:

  • 您说,“到目前为止,我所做的是显示当前数据并且它显示完美”您是在视图控制器上显示数据吗?
  • @iamyogish 是的,数据显示在视图控制器上
  • 然后你可以使用 UIPageViewController 来实现你想要的。
  • @iamyogish 会调查的!谢谢

标签: ios xcode swift swipe uiswipegesturerecognizer


【解决方案1】:
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
        }
    }
}

【讨论】:

  • 在上面的示例代码中,您可以只使用一个手势识别器并将方向设置如下swipeRight.direction = [UISwipeGestureRecognizerDirection.left, UISwipeGestureRecognizerDirection.right]
  • 我收到信号 SIGABRT :(
猜你喜欢
  • 2011-03-29
  • 2019-04-16
  • 1970-01-01
  • 2013-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-27
  • 2011-10-06
相关资源
最近更新 更多