ios is it possible for a uiscrollview to detect a single tap by a user while still providing its dragging, scrolling capabilities?
Use the following code for your scrollView object :
UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
singleTapGestureRecognizer.numberOfTapsRequired = 1;
singleTapGestureRecognizer.enabled = YES;
singleTapGestureRecognizer.cancelsTouchesInView = NO;
[scrollView addGestureRecognizer:singleTapGestureRecognizer];
//[singleTapGestureRecognizer release]; Not needed in ARC-enabled Project
}
- (void)singleTap:(UITapGestureRecognizer *)gesture {
//handle taps
}
Swift 5
let scrollViewTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(scrollViewTapped(_:)))
scrollViewTapGestureRecognizer.numberOfTapsRequired = 1
scrollViewTapGestureRecognizer.isEnabled = true
scrollViewTapGestureRecognizer.cancelsTouchesInView = false
scrollView.addGestureRecognizer(scrollViewTapGestureRecognizer)
@objc func scrollViewTapped(_ sender: UITapGestureRecognizer) {
print("UIScrollView was tapped.")
}