gpt4 book ai didi

ios - 如何检测滑动手势方向?

转载 作者:IT王子 更新时间:2023-10-29 08:04:14 26 4
gpt4 key购买 nike

我需要检测我的滑动手势的方向,但我遇到了问题。手势有效,但我不知道如何检测方向。 ...

swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(detectSwipe:)];
[swipeGesture setNumberOfTouchesRequired:1];
[swipeGesture setDirection:UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp];
[appView addGestureRecognizer:swipeGesture];

-(void)detectSwipe:(UISwipeGestureRecognizer *)recognizer {
switch (recognizer.direction) {
case UISwipeGestureRecognizerDirectionUp:
NSLog(@"smth1");
break;


case UISwipeGestureRecognizerDirectionDown:
NSLog(@"smth2");
default:
break;
}
}

它不工作:/

最佳答案

这是我的一个项目中的示例:

    // ...

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

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

UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeUp];

UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeDown];

// ...

- (void)didSwipe:(UISwipeGestureRecognizer*)swipe{

if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"Swipe Left");
} else if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
NSLog(@"Swipe Right");
} else if (swipe.direction == UISwipeGestureRecognizerDirectionUp) {
NSLog(@"Swipe Up");
} else if (swipe.direction == UISwipeGestureRecognizerDirectionDown) {
NSLog(@"Swipe Down");
}
}

关于ios - 如何检测滑动手势方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8813021/

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