2012-06-25 57 views
2

我有两个UIButtons在表格单元格中滚动时不方便按下。我怎样才能防止这一点?滚动时阻止UIButton按下

是否有一些属性或发送的事件可以设置,因此只有在用户按下按钮时才按下按钮,而不是在按下按钮时才按下按钮?

我玩过各种不同的触摸事件(Touch Up Inside和Touch Down),但似乎都无法解决此问题。

回答

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

如果按下按钮时,你已经在滚动这工作。我遇到的真正问题是,如果您在按钮上方开始滚动手势,即使您在按钮外释放,也会触发按钮。 – mnort9

0

在Interface Builder中更改按键的标签值一个大于10(或某个值)的数字。子类的UIScrollView和超越:

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

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

}

你的滚动视图应该具备的使用性能canCancelContentTouches设置为yes并且delaysContentTouches设置为NO