UIButton Doesn't allow UIScrollView to scroll
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;
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)
}