iOS 水平 CollectionView 没有一直滚动
iOS Horizontal CollectionView not scrolling all the way
我有一行 collectionview
水平滚动。 collectionview
有效,但它会切断倒数第二个单元格(标记为橙色)并隐藏最后一个单元格。
我有 5 个单元格,每个单元格的大小为 166x166。我已经检查了 viewlayout
的 contentsize
,它的宽度是 830,这是正确的,但我无法滚动那么远。
Storyboard 中的设置如下:
这里是 collectionview
的代码。
#pragma mark Collection View Methods
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [array count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FeaturedCell" forIndexPath:indexPath];
UILabel *label = (UILabel *) [cell viewWithTag: 100];
label.text = [array objectAtIndex:indexPath.row];
[cell.layer setBorderWidth:2.0f];
[cell.layer setBorderColor:[UIColor whiteColor].CGColor];
return cell;
}
新的 IB 视图大小默认值是 600 点。如果您不使用自动布局或其他方式来限制尺寸,框架将延伸出屏幕并且不可见。如果这种情况发生在 320 像素宽处,您将损失 240 点,如果您的单元格宽度为 166 点,则意味着您将损失大约 1 1/2 单元格。关于缺少什么。
确保 collection view 有一个到 superview 边缘的尾部约束为常量 0(或其他确保大小匹配的方法,例如 "equal" 到 superview 的宽度)。
将 minimumLineSpacing
和 minimumInteritemSpacing
设置为相等的值解决了我的水平集合视图问题。
我有一行 collectionview
水平滚动。 collectionview
有效,但它会切断倒数第二个单元格(标记为橙色)并隐藏最后一个单元格。
我有 5 个单元格,每个单元格的大小为 166x166。我已经检查了 viewlayout
的 contentsize
,它的宽度是 830,这是正确的,但我无法滚动那么远。
Storyboard 中的设置如下:
这里是 collectionview
的代码。
#pragma mark Collection View Methods
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [array count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FeaturedCell" forIndexPath:indexPath];
UILabel *label = (UILabel *) [cell viewWithTag: 100];
label.text = [array objectAtIndex:indexPath.row];
[cell.layer setBorderWidth:2.0f];
[cell.layer setBorderColor:[UIColor whiteColor].CGColor];
return cell;
}
新的 IB 视图大小默认值是 600 点。如果您不使用自动布局或其他方式来限制尺寸,框架将延伸出屏幕并且不可见。如果这种情况发生在 320 像素宽处,您将损失 240 点,如果您的单元格宽度为 166 点,则意味着您将损失大约 1 1/2 单元格。关于缺少什么。
确保 collection view 有一个到 superview 边缘的尾部约束为常量 0(或其他确保大小匹配的方法,例如 "equal" 到 superview 的宽度)。
将 minimumLineSpacing
和 minimumInteritemSpacing
设置为相等的值解决了我的水平集合视图问题。