Ios UICollectionview不是';t当布局水平时加载单元格,直到图幅足够大
我的所有代理都连接起来并调用一个垂直布局对象。在水平模式下,由于某些原因,唯一调用的委托是Ios UICollectionview不是';t当布局水平时加载单元格,直到图幅足够大,ios,objective-c,uicollectionview,ios7,uicollectionviewlayout,Ios,Objective C,Uicollectionview,Ios7,Uicollectionviewlayout,我的所有代理都连接起来并调用一个垂直布局对象。在水平模式下,由于某些原因,唯一调用的委托是numberofcellsincollectionview(返回正确的数字)-cellforitematindexpath,除非我增加collectionview框架的大小,否则不会调用该委托。当它足够大时,调用cellforitematindexpath。这种奇怪的行为只有在collectionview布局处于水平模式时才会发生。在垂直模式下,不获取此行为。(而且这种奇怪的行为只在iOS7中开始-不知道是
numberofcellsincollectionview
(返回正确的数字)-cellforitematindexpath
,除非我增加collectionview框架的大小,否则不会调用该委托。当它足够大时,调用cellforitematindexpath。这种奇怪的行为只有在collectionview布局处于水平模式时才会发生。在垂直模式下,不获取此行为。(而且这种奇怪的行为只在iOS7中开始-不知道是否存在连接)
水平布局代码
-(UICollectionViewFlowLayout *)getFilmStripLayout
{
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[flowLayout setSectionInset:UIEdgeInsetsMake(0, 0, 0, 0)];
CGSize s = CGSizeMake(self.frame.size.height,self.frame.size.height);
[flowLayout setItemSize:s];
return flowLayout;
}
包含视图的视图控制器
-(UIThumbnailGalleryView *)gallery
{
if (_gallery == nil)
{
CGRect r = CGRectInset(self.filmStripRect, 0, -20); // started with inset 0,0 , increased the size and then the delegates are called.
_gallery = [[UIThumbnailGalleryView alloc] init2WithFrame:r]; // custom initializer testing layouts
[_gallery setBackgroundColor:[UIColor clearColor]];
[_gallery setBackgroundColor:[UIColor purpleColor]]; // setting colors in order to see the placement
_gallery.layer.borderColor = [UIColor orangeColor].CGColor;
_gallery.layer.borderWidth = 3;
_gallery.dataSource = self;
_gallery.delegate = self;
[_gallery setInToggleMode:YES];
}
return _gallery;
}
我也注意到了水平布局的奇怪行为,特别是在故事板中关于如何处理滚动视图插入的行为。这很可能是一个苹果虫。如果视图不够大,无法容纳单元格,则永远不会调用cellForItemAtIndexPath(这是预期行为)。尝试在视图控制器上设置
automaticallyadjustsscrollviewsinsets
,看看这是否为您解决了问题。@AndrewTheis您救了我一天!将automaticallyaadjustsscrollviewsinsets
设置为false
对我起了作用。