I have many UIButtons
within a UIScrollView
. Those UIButtons
have actions attached to them in Touch Down Repeat
. My problem
As long as you have the Cancellable Content Touches
in Interface Builder set it should work. You can also set it in code:
scrollView.canCancelContentTouches = YES;
Use a UITapGestureRecognizer
with delaysTouchesBegan
as a property set to true
.
So view.canCancelContentTouches = YES
works OK if you don't also have delaysContentTouches
set to YES
. If you do though, the buttons won't work at all. What you need to do is subclass the UIScrollView
(or UICollectionView
/UITableView
) and implement the following:
Objective-C
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
if ([view isKindOfClass:UIButton.class]) {
return YES;
}
return [super touchesShouldCancelInContentView:view];
}
Swift 2
override func touchesShouldCancelInContentView(view: UIView) -> Bool {
if view is UIButton {
return true
}
return super.touchesShouldCancelInContentView(view)
}