gpt4 book ai didi

ios - 我想快速左右滑动

转载 作者:搜寻专家 更新时间:2023-10-31 21:55:37 24 4
gpt4 key购买 nike

我在 xcode 7 ( swift ) 中有一个项目,我想加载在 Storyboard 中设计的不同 View Controller ,其功能是左右滑动,然后转到下一个 View Controller 或返回。现在我有了这个,但只从右到左淡入,我想要两个淡入。

func respondToSwipeGesture(sender: UISwipeGestureRecognizer) {

switch sender.direction {
case UISwipeGestureRecognizerDirection.Right:
print("SWIPED DERECHA")
self.performSegueWithIdentifier("cambio2", sender: nil)
case UISwipeGestureRecognizerDirection.Left:
print("SWIPED IZQUIERDA")
self.performSegueWithIdentifier("cambio", sender: nil)
default:
break
}
}

最佳答案

您还可以通过创建它的 2 个实例来使用 UISwipeGestureRecognizer。每个方向一个。

    var swipeLeft : UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipe:")
swipeLeft.direction = UISwipeGestureRecognizerDirection.Left

var swipeRight : UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipe:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Right

self.view.addGestureRecognizer(swipeLeft)
self.view.addGestureRecognizer(swipeRight)

和滑动功能

func swipe(sender: UISwipeGestureRecognizer) {

switch sender.direction {
case UISwipeGestureRecognizerDirection.Right:
print("SWIPED DERECHA")
self.performSegueWithIdentifier("first", sender: nil)
case UISwipeGestureRecognizerDirection.Left:
print("SWIPED IZQUIERDA")
self.performSegueWithIdentifier("second", sender: nil)
default:
break
}
}

关于ios - 我想快速左右滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32855753/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com