【发布时间】:2011-07-01 12:08:16
【问题描述】:
UIScrollView 中有很多 UIButtons。那些UIButtons 在Touch Down Repeat 中附加了操作。我的问题是当我触摸按钮然后滚动时我的滚动视图不滚动,但如果我触摸按钮外部它工作正常。
即使按下按钮,我怎样才能让我的滚动视图滚动?
【问题讨论】:
标签: iphone ios uiscrollview uibutton
UIScrollView 中有很多 UIButtons。那些UIButtons 在Touch Down Repeat 中附加了操作。我的问题是当我触摸按钮然后滚动时我的滚动视图不滚动,但如果我触摸按钮外部它工作正常。
即使按下按钮,我怎样才能让我的滚动视图滚动?
【问题讨论】:
标签: iphone ios uiscrollview uibutton
只要您在 Interface Builder 中设置了 Cancellable Content Touches,它就应该可以工作。也可以在代码中设置:
scrollView.canCancelContentTouches = YES;
【讨论】:
Delay Content Touches 属性和文档,它们可能也与您正在做的事情有关。
所以如果您没有将delaysContentTouches 设置为YES,view.canCancelContentTouches = YES 工作正常。但是,如果您这样做,按钮将根本不起作用。您需要做的是继承UIScrollView(或UICollectionView/UITableView)并实现以下内容:
Objective-C
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
if ([view isKindOfClass:UIButton.class]) {
return YES;
}
return [super touchesShouldCancelInContentView:view];
}
斯威夫特 2
override func touchesShouldCancelInContentView(view: UIView) -> Bool {
if view is UIButton {
return true
}
return super.touchesShouldCancelInContentView(view)
}
【讨论】:
使用UITapGestureRecognizer 和delaysTouchesBegan 作为属性设置为true。
【讨论】: