我在表格单元格中有两个UIButton,在滚动时不方便按下。我怎么能阻止这个?
是否有我可以设置的属性或已发送事件,因此只有在用户释放按键时才按下按钮,而不是按下按钮后立即按下按钮?
我玩过不同的触摸事件(Touch Up Inside和Touch Down),似乎都没有解决这个问题。
答案 0 :(得分:3)
您可以收听tableview的滚动委托回调并关闭正在滚动的按钮
- (void)scrollViewWillBeginDragging:(UIScrollView *)activeScrollView {
//I assume the buttons are within your cells so you will have to enable them within your cells so you will probably have to handle this by sending a custom message to your cells or accessing them with properties.
[yourButton setEnabled: NO];
}
并倾听
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
// do the same to enable them back
[yourButton setEnabled: YES];
}
答案 1 :(得分:0)
在界面构建器中,将按钮的标记值更改为大于10的数字(或某个值)。子类UIScrollView并覆盖:
-(BOOL) touchesShouldCancelInContentView:(UIView *)view {
if(view.tag>10) {
NSLog(@"should A");
return YES;
} else return NO;
}
您的scrollView应将属性canCancelContentTouches
设置为YES,将delaysContentTouches
设置为NO