简体   繁体   中英

iOS7 UICollectionView in scroll direction horizontal isn't working

Same code for iOS6 worked fine.

For some reason when updating to iOS7 and using this layout

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. 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. 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. When making the frame larger (in horizontal or vertical mode) the collectionview "fills" the scrollview and the delegates are called

normal size collectionview (no cells and delegate aren't called)

在此处输入图片说明

enlarged the frame by 50 px

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 :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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