我正在使用下面的代码将右/左滑动事件集成到 UIImageView 对象(称为photo_view),但在 iphone 模拟器和设备中测试后它没有工作。下面的方法handleLeftSwipe和handleRightSwipe甚至没有被调用,因为日志没有在调试器日志中打印任何它应该的东西。这是代码:
- (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");
}
知道是什么原因吗?
提前感谢您的帮助,
斯蒂芬妮