2

我正在使用下面的代码将右/左滑动事件集成到 UIImageView 对象(称为photo_view),但在 iphone 模拟器和设备中测试后它没有工作。下面的方法handleLeftSwipehandleRightSwipe甚至没有被调用,因为日志没有在调试器日志中打印任何它应该的东西。这是代码:

- (void)viewDidLoad
{
     [super viewDidLoad];

     UISwipeGestureRecognizer *leftSwipeRecognizer = [[UISwipeGestureRecognizer alloc]  initWithTarget:self action:@selector(handleLeftSwipe:)];
     leftSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
     leftSwipeRecognizer.numberOfTouchesRequired = 1;
     [photo_view addGestureRecognizer:leftSwipeRecognizer];
     leftSwipeRecognizer.delegate = self;
     [leftSwipeRecognizer release];

     UISwipeGestureRecognizer *rightSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];
     rightSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
     rightSwipeRecognizer.numberOfTouchesRequired = 1;
     [photo_view addGestureRecognizer:rightSwipeRecognizer];
     rightSwipeRecognizer.delegate = self;
     [rightSwipeRecognizer release];

}


- (void)handleLeftSwipe:(UISwipeGestureRecognizer *)recognizer
{
     NSLog(@"handleLeftSwipe called");
}

- (void)handleRightSwipe:(UISwipeGestureRecognizer *)recognizer
{
     NSLog(@"handleRightSwipe called");
}

知道是什么原因吗?

提前感谢您的帮助,

斯蒂芬妮

4

2 回答 2

7

UIImageView实例默认userInteractionEnabledNO. 尝试将其设置为YES.

于 2011-11-04T15:30:09.860 回答
2

确保您还包括<UIGestureRecognizerDelegate>在您的 .h 文件中。

于 2013-04-24T07:03:41.857 回答