我正在使用UICollectionView. 这很简单:AUIView以UICollectionView编程方式创建,UICollectionViewFlowLayout与一个部分一起使用,滚动设置为水平。它出现在屏幕上,并在正确的单元格中包含正确的数据。但它不滚动——事实上它根本不响应用户交互。
这是视图的初始化程序:
- (id)initWithFrame:(CGRect)frame andItemData:(NSArray *)itemData
{
self = [super initWithFrame:frame];
if (self) {
_itemData = itemData;
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[flowLayout setItemSize:CGSizeMake(kCellWidth, kCellHeight)];
[flowLayout setMinimumInteritemSpacing:0.f];
[flowLayout setMinimumLineSpacing:0.f];
_collectionView = [[UICollectionView alloc] initWithFrame:[self frame] collectionViewLayout:flowLayout];
[_collectionView setDataSource:self];
[_collectionView setDelegate:self];
[_collectionView setBounces:NO];
[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"HorizontalPickerCell"];
[self addSubview:_collectionView];
}
return self;
}
我尝试以编程方式设置UserInteractionEnabled为YES,但这没有任何区别(也不应该有,因为默认UserInteractionEnabled设置为YES)。FWIW,集合视图使用标准UICollectionViewCell的UILabels 添加到他们contentView的 s 作为子视图。
关于为什么这不是滚动的任何想法?非常感谢任何和所有帮助。