gpt4 book ai didi

ios - UISwipeGestureRecognizerDirection 仅识别正确的手势

转载 作者:行者123 更新时间:2023-11-29 01:55:40 26 4
gpt4 key购买 nike

我正在尝试向 UITableView 中的每个单元格添加左右滑动手势。然而,无论我往哪里看,似乎都没有人回答这个问题。使用当前推荐的解决方案,我没有输入正确的手势处理程序。

UISwipeGestureRecognizer* right = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
right.direction = UISwipeGestureRecognizerDirectionRight;
[self.tableView addGestureRecognizer:right];


UISwipeGestureRecognizer* left = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)];
left.direction = UISwipeGestureRecognizerDirectionLeft;
[self.tableView addGestureRecognizer:left];

我为我的解决方案创建了两个不同的手势识别器。但是,我永远看不到来自正确的 UIGestureRecognizer 的响应。我不明白为什么我从未看到右侧手势识别器的响应,而只看到左侧手势识别器的响应。

-(void)swipeLeft:(UISwipeGestureRecognizer*)gestureRecognizer
{ NSLog("You have swiped Left");
}
-(void)swipeRight:(UISwipeGestureRecognizer*)gestureRecognizer
{ NSLog("You have swiped right"); //Never Enter this handler
}

最佳答案

使用此代码...

我希望你不要介意它很快。

override func viewDidLoad() {
super.viewDidLoad()

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

var swipeDown = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeDown.direction = UISwipeGestureRecognizerDirection.Down
self.view.addGestureRecognizer(swipeDown)
}

func respondToSwipeGesture(gesture: UIGestureRecognizer) {

if let swipeGesture = gesture as? UISwipeGestureRecognizer {

switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.Right:
println("Swiped right")
case UISwipeGestureRecognizerDirection.Down:
println("Swiped down")
default:
break
}
}
}

关于ios - UISwipeGestureRecognizerDirection 仅识别正确的手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30897834/

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