【发布时间】:2012-06-26 22:57:32
【问题描述】:
我在表格单元格中有两个 UIButton,滚动时按下不便。我怎样才能防止这种情况?
我是否可以设置一些属性或发送事件,以便仅在用户释放按下时才按下按钮,而不是在按下按钮时按下?
我尝试了不同的触摸事件(Touch Up Inside 和 Touch Down),但似乎都没有解决这个问题。
【问题讨论】:
标签: iphone ios uiscrollview uibutton
我在表格单元格中有两个 UIButton,滚动时按下不便。我怎样才能防止这种情况?
我是否可以设置一些属性或发送事件,以便仅在用户释放按下时才按下按钮,而不是在按下按钮时按下?
我尝试了不同的触摸事件(Touch Up Inside 和 Touch Down),但似乎都没有解决这个问题。
【问题讨论】:
标签: iphone ios uiscrollview uibutton
您可以监听 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];
}
【讨论】:
在界面生成器中,将按钮的标记值更改为大于 10 的数字(或某个值)。子类 UIScrollView 并覆盖:
-(BOOL) touchesShouldCancelInContentView:(UIView *)view {
if(view.tag>10) {
NSLog(@"should A");
return YES;
} else return NO;
}
您的 scrollView 应该将属性 canCancelContentTouches 设置为 YES 并将 delaysContentTouches 设置为 NO
【讨论】: