我将两个滑动手势拖到我的 View Controller 中的 ImageView 中,一个用于向右滑动,另一个用于向左滑动。然后我将它们作为 IBAction 连接到 View Controller 的头文件。我在 IBAction 方法中写了一些代码,但问题是当我在运行应用程序时向左/向右滑动时,它永远不会被调用。这是一个代码示例:
- (IBAction)handleSwipe:(UISwipeGestureRecognizer *)sender
{
NSLog(@"swiped");
NSArray *images;
if (self.selectedRow == 0) {
images = [[NSArray alloc] initWithObjects:@"w8.JPG",@"w7.JPG",@"w6.JPG",@"w5.JPG",@"w4.JPG",@"w3.JPG", @"w2.JPG", @"w1.JPG" ,@"w9.JPG", nil];
UISwipeGestureRecognizerDirection direction = [(UISwipeGestureRecognizer *) sender direction];
switch (direction) {
case UISwipeGestureRecognizerDirectionRight:
imageIndex++;
break;
case UISwipeGestureRecognizerDirectionLeft:
imageIndex--;
break;
default:
break;
}
imageIndex = (imageIndex < 0) ? ([images count] - 1): imageIndex % [images count];
self.imageView.image = [UIImage imageNamed:[images objectAtIndex:imageIndex]];
}
}
NSLog 从未显示过,所以我确信发送者没有发送到该方法。 另一件事是我曾经在 Xcode 5 中运行相同的代码并且一切正常,最近我将我的 Xcode 更新到版本 6。 我应该怎么做才能解决这个问题?
最佳答案
我发现了问题所在。在 ImageView 的属性检查器中,未选中“启用用户交互”,我启用了它。现在滑动手势可以正常工作了。
关于ios - 在模拟器中滑动时,UISwipeGestureRecognizer 不会发送到 IBAction 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26482560/