objective-c - UISwipeGestureRecognizer 没有按预期工作

标签 objective-c ios uiswipegesturerecognizer

因此,我正在尝试向我的应用程序屏幕上的其中一个 subview 添加滑动手势。我声明手势识别器如下:

UISwipeGestureRecognizer *swiperR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(switchStackingMode:)];
    [swiperR setDirection:UISwipeGestureRecognizerDirectionRight];
    [chart addGestureRecognizer:swiperR];

UISwipeGestureRecognizer *swiperL = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(switchStackingMode:)];
    [swiperL setDirection:UISwipeGestureRecognizerDirectionLeft];
    [chart addGestureRecognizer:swiperL];


-(void)switchStackingMode:(UISwipeGestureRecognizer *)sender {
    NSLog(@"inside switchstack from gesture");
    //other stuff
}

当我尝试在应用程序启动时与 subview 交互时,只有滑动手势 swiperL 有效。我向右滑动没有任何反应。我最初尝试只做一个带方向的手势识别器 (UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight) 但那没有用,并且基于其他堆栈溢出答案我恢复到两个单独的识别器。仍然没有运气,这让我感到困惑。我觉得我错过了什么..

最佳答案

此代码应该有效。你在试用设备吗?在模拟器中滑动手势不是那么容易。

您只能做一个同时识别左右的手势。 这种方式适用于左右或上下,但不适用于所有方向。

关于objective-c - UISwipeGestureRecognizer 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11561962/

相关文章:

objective-c - 从 NSDictionary 中提取信息

ios - 如何从 TabBar Controller 禁用滑动手势识别器

iphone - 导入指令不允许访问该类

ios - 通过FacebookSDK.framework登录时未获取电子邮件ID

ios - 我如何调试此错误 : CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER?

ios - 从 ScrollView 委托(delegate)分配 alpha

iphone - 我如何从苹果崩溃报告中找到内存位置?我的应用程序崩溃的地方。?

iphone - UISwipeGestureRecognizerDirection 问题

ios - 使用 Swift 的带有 SpriteKit 的 UISwipeGestureRecognizer

objective-c - 热键?关键事件?