[英]UITableView does not respond to touches at transparent areas
I have a UITableView
with a transparent backgroundColor
, and the cells inside are initialized with the following code 我有一个带透明
backgroundColor
的UITableView
,里面的单元格用以下代码初始化
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, CGRectGetWidth(self.contentView.frame), 180)];
self.label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.label.text = @"test";
[self.contentView addSubview:self.label];
}
return self;
}
Each row has a height of 200, and the label doesn't fill up the entire cell. 每行的高度为200,标签不会填满整个单元格。 There will be transparent portions in between each cell.
每个单元格之间将有透明部分。 When I try to scroll the table by touching those transparent portions, the touches are completely ignored.
当我尝试通过触摸那些透明部分来滚动表格时,触摸完全被忽略。 I am aware that as of iOS5, touches on views will be ignored.
我知道,从iOS5开始,对视图的触摸将被忽略。 What can I do to solve this?
我该怎么做才能解决这个问题?
Things I've tried that don't work: 我尝试过的东西不起作用:
Setting a transparent or hidden or alpha = 0 UIView
to act as a fake background of the tableView 设置透明或隐藏或alpha = 0
UIView
作为tableView的假背景
Same deal, touches are ignored. 相同的交易,触摸被忽略。
Creating a subclassed UIView
on top of the tableView, and the subclassed UIView
uses tableView as the nextResponder 在tableView之上创建一个子类
UIView
,子类UIView
使用tableView作为nextResponder
Apparently UITableView
doesn't use touchesBegan/cancelled/ended/moved, so this doesn't work. 显然
UITableView
不使用touchesBegan / canceled / ends / moved,所以这不起作用。 I don't think it's wise to implement my methods to scroll the UITableView
either. 我认为实现滚动
UITableView
方法并不明智。
Setting the backgroundColor of the tableView to [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1]
将tableView的backgroundColor设置为
[UIColor colorWithRed:0 green:0 blue:0 alpha:0.1]
I don't want to do this, it's still visible. 我不想这样做,它仍然可见。
In short, what can I do to scroll the table even when I start the scrolling from the transparent section? 简而言之, 即使我从透明部分开始滚动 , 我还能做些什么来滚动表?
First you create a label with no text(or a view) such that it completely fills the cell. 首先,创建一个没有文本(或视图)的标签,使其完全填充单元格。 Then create a new label with your text and add this as a subview of the first view.
然后使用您的文本创建一个新标签,并将其添加为第一个视图的子视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.