Swift:检测与iOS 7兼容的滑动手势

时间:2015-05-23 09:34:28

标签: ios swift

我使用此代码检测滑动手势:

    let swipeRight = UISwipeGestureRecognizer(target: self, action: Selector("rightSwiped"))
    swipeRight.direction = UISwipeGestureRecognizerDirection.Right
    self.matn.addGestureRecognizer(swipeRight)

    let swipeLeft = UISwipeGestureRecognizer(target: self, action: Selector("leftSwiped"))
    swipeLeft.direction = UISwipeGestureRecognizerDirection.Left
    self.matn.addGestureRecognizer(swipeLeft)

    let swipeDown = UISwipeGestureRecognizer(target: self, action: Selector("downSwiped"))
    swipeDown.direction = UISwipeGestureRecognizerDirection.Down
    self.matn.addGestureRecognizer(swipeDown)

    let swipeUp = UISwipeGestureRecognizer(target: self, action: Selector("upSwiped"))
    swipeUp.direction = UISwipeGestureRecognizerDirection.Up
    self.matn.addGestureRecognizer(swipeUp)

func rightSwiped(sender:UISwipeGestureRecognizer)
{
    println("right swiped ")
}

func leftSwiped()
{
    println("left swiped ")
}

func downSwiped()
{
    println("down swiped ")
}

func upSwiped()
{
    println("Up swiped ")
}

enter image description here 但{8}在iOS8及更高版本中可用。UISwipeGestureRecognizerDirection。如何使其与iOS7兼容?

1 个答案:

答案 0 :(得分:0)

正如Wain在评论Direction has been available since 3.2中所提到的,所以你可以在iOS 7中使用它。我已经测试了你的代码,并且它与Deployment target 7.0一起工作正常。所以你可以在iOS 7中使用它。