iphone - UISwipeGestureRecognizer 无需触摸

标签 iphone ios objective-c uigesturerecognizer

我如何识别UISwipeGestureRecognizerUISwipeGestureRecognizerDirectionUp然后紧接着,无需抬起手指,就识别出 UISwipeGestureRecognizerDirectionDown识别器?

基本上我想要多个UISwipeGestureRecognizers当我改变方向时,无需抬起手指即可识别。

到目前为止我的代码...

    - (void)viewDidLoad {        
        UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(screenSwipedUp)];
        swipeUp.numberOfTouchesRequired = 1;
        swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
        swipeUp.cancelsTouchesInView = NO;
        [self.view addGestureRecognizer:swipeUp];

        UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(screenSwipedDown)];
        swipeDown.numberOfTouchesRequired = 1;
        swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
        swipeDown.cancelsTouchesInView = NO;
        [self.view addGestureRecognizer:swipeDown];

    }

    - (void)screenSwipedUp {
        NSLog(@"SW-Up");
    }

    - (void)screenSwipedDown {
        NSLog(@"SW-Down");
    }

最佳答案

我认为你不能用 UISwipeGestureRecognizer 做到这一点.您可以改为使用 UIPanGestureRecognizer并实现该操作或创建 UIGestureRecognizer 的子类和 Override the methods识别您的特殊手势。

关于iphone - UISwipeGestureRecognizer 无需触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15997381/

相关文章:

Objective-C - block 和内存管理?

iphone - 另一个 Xcode 项目中的 undefined symbol

iphone - 向 iPhone 中的 UIImage 添加类别

ios - iOS 开发新手 - 农业 map 应用

ios - iOS 应用程序的 iCloud 服务器空间限制

ios - 自动布局:UIImageView 不随设备方向旋转

objective-c - -[国家保留] : message sent to deallocated instance 0x6829280

iphone - NSDateFormatter 和日本日历

iphone - 如何在 iOS 中使用 Objective-C 加入路径片段?

ios - viewDidUnload 与 viewDidDisappear