【发布时间】:2013-05-21 00:01:52
【问题描述】:
我正在构建一个 UITableView,它在 tableview 的部分标题中有一个按钮,因此当用户向下滚动屏幕时,该按钮被固定在屏幕顶部。
问题在于,当 UITableView 移动时,节标题按钮的触摸事件没有注册。如果 tableview 不滚动,按钮只会获取触摸事件。
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (!_sectionHeaderView) {
_sectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(0, 0, 50, 50);
[backButton setImage:[UIImage imageNamed:@"upArrow"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(scrollToTop:) forControlEvents:UIControlEventTouchUpInside];
[_sectionHeaderView addSubview:backButton];
}
return _sectionHeaderView;
}
目前,发生的情况是: - 如果 tableview 没有滚动,按钮会按预期执行:点击它,按钮会获得 TouchUpInside 手势。 - 如果 tableview 正在滚动,则按钮不会获得 TouchUpInside 手势 - 相反,tableview 会停止在原地。
我尝试将 UITableView 子类化并查看 touchesBegan: 方法等,但没有成功。我看到了相同的模式:手势仅在 tableview 不移动时显示。
更新: 这不是可用性问题 - 虽然我无法显示我正在处理的设计的屏幕截图,但在部分标题中使用按钮和控件是一个有效的用例。
这里有一个简单的草图来解释原因:
【问题讨论】:
-
这会导致糟糕的用户体验,正如@Undo 已经提到的,我强烈建议不要这样做。
-
@Stunner 我已经用图片更新了问题,以阐明用户体验
-
啊,我明白了……现在更有意义了。
标签: iphone ios uitableview