简体   繁体   English

水平滚动方向上的iOS7 UICollectionView不起作用

[英]iOS7 UICollectionView in scroll direction horizontal isn't working

Same code for iOS6 worked fine. iOS6的相同代码工作正常。

For some reason when updating to iOS7 and using this layout 由于某些原因,更新到iOS7并使用此布局时

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];

    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
 /
    CGSize s = CGSizeMake(self.collectionView.frame.size.height,self.collectionView.frame.size.height);

    [flowLayout setItemSize:s];

the collectionview delegate methods aren't called. 没有调用collectionview委托方法。 I changed the scroll direction to vertical, all delegates are called, I changed the frame size of the collectionview to be larger and the delegate methods are called. 我将滚动方向更改为垂直,调用了所有委托,将collectionview的框架大小更改为更大,并调用了委托方法。 I suspect that the collectionview is for somereason offset inside its content view, causing the cells to be offscreen, inturn the delegates aren't called. 我怀疑collectionview在其内容视图中存在一定程度的偏移,导致单元格不在屏幕上,从而不会调用委托。 When making the frame larger (in horizontal or vertical mode) the collectionview "fills" the scrollview and the delegates are called 当使框架变大时(在水平或垂直模式下),collectionview“填充” scrollview,并调用委托

normal size collectionview (no cells and delegate aren't called) 正常大小的collectionview(不调用任何单元格和委托)

在此处输入图片说明

enlarged the frame by 50 px 将框架放大50像素

CGRect r = CGRectInset(self.filmStripRect, 0, -50);

cells appear and delegates are called 出现单元格并调用代表

在此处输入图片说明

您还应该检查这些内容以使水平滚动工作:

we should create a new CollectionViewLayout , and resign it to the collectionView : 我们应该创建一个新的CollectionViewLayout ,并将其辞职到collectionView

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
self.collectionView.collectionViewLayout = flowLayout;
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[CollectionData setCollectionViewLayout:flowLayout];

If you are using storyboard,select a collectionview,go to attribute inspector an set the scroll direction horizontal. 如果使用情节提要,请选择一个collectionview,然后将属性检查器设置为水平滚动方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM