gpt4 book ai didi

快速滑动识别器在第一次滑动时不起作用

转载 作者:搜寻专家 更新时间:2023-11-01 05:36:05 24 4
gpt4 key购买 nike

这是我的代码我想要左滑和右滑两个功能这两个功能都有效,但只有当我滑动两次时……第一次没有任何反应谢谢!

override func viewWillAppear(animated: Bool) {

SwipeGesture.addTarget(self, action: "addSwipe")
}

func addSwipe() {
let directions: [UISwipeGestureRecognizerDirection] = [.Right, .Left]
for direction in directions {
let gesture = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipe:"))
gesture.direction = direction
self.view.addGestureRecognizer(gesture)
}
}

func handleSwipe(sender: UISwipeGestureRecognizer) {
switch sender.direction {
case UISwipeGestureRecognizerDirection.Right:
print("swipe to close")
self.dismissViewControllerAnimated(true, completion: nil)

case UISwipeGestureRecognizerDirection.Left:
print("Swiped left")

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let resultViewController = storyBoard.instantiateViewControllerWithIdentifier("chatAlbumViewController") as UIViewController
self.presentViewController(resultViewController, animated:true, completion:nil)
default:
break
}
}

最佳答案

你需要滑动两次的原因是因为你有一个添加手势识别器的手势识别器,所以第一次滑动注册它们然后第二次实际上做你想要的。

要修复,请更改此代码:

override func viewWillAppear(animated: Bool) {

SwipeGesture.addTarget(self, action: "addSwipe")
}

override func viewWillAppear(animated: Bool) {

self.addSwipe()
}

然后把另一个的 socket 拔掉,不需要了

关于快速滑动识别器在第一次滑动时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39467881/

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