2

我在表格单元格中有两个 UIButtons,滚动时不方便按下。我怎样才能防止这种情况?

是否有一些属性或发送事件我可以设置,以便仅在用户释放按下时按下按钮,而不是在按下按钮时按下?

我尝试了不同的触摸事件(Touch Up Inside 和 Touch Down),但似乎都没有解决这个问题。

4

2 回答 2

3

You can listen for the tableview's scrolling delegate callbacks and turn off your buttons they are being scrolled

- (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];
}

and listen for

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
   // do the same to enable them back
   [yourButton setEnabled: YES];
}
于 2012-06-25T16:49:11.610 回答
0

在界面生成器中,将按钮的标记值更改为大于 10 的数字(或某个值)。子类 UIScrollView 并覆盖:

-(BOOL) touchesShouldCancelInContentView:(UIView *)view {

if(view.tag>10) {
    NSLog(@"should A");
    return YES;
} else return NO;

}

您的 scrollView 应该将属性canCancelContentTouches设置为 YES 并delaysContentTouches设置为 NO

于 2012-06-25T17:17:45.133 回答