我添加了一个帧大小为320x600的UICollectionView,每个项目大小为44x44。最终的输出不能正确定位每行中的单元格。有一些单元格位于收集视图的边界之外,它看起来像该链接中的图像:http://cl.ly/image/2s270g1p1g2eiOS6 - UICollectionViewFlowLayout不能正确放置单元格
#4,#5,#6,#11,#12,#13和其他在收集视图的界限之外。这里是我的我的UICollectionView的发起和流布局的代码:
SSCalendarFlowLaout *flowlayout = [[SSCalendarFlowLaout alloc] init];
flowlayout.minimumInteritemSpacing = 1.0f;
flowlayout.minimumLineSpacing = 1.0f;
flowlayout.itemSize = CGSizeMake(44, 44);
flowlayout.scrollDirection = UICollectionViewScrollDirectionVertical;
CGRect rect = CGRectMake(0, 0, 320, 600);
self.calendarGrids = [[UICollectionView alloc] initWithFrame:rect
collectionViewLayout:flowlayout];
self.calendarGrids.delegate = self;
self.calendarGrids.dataSource = self;
self.calendarGrids.allowsSelection = YES;
self.calendarGrids.backgroundColor = [UIColor yellowColor];
[self.calendarGrids registerClass:[SSCalendarDayCell class]
forCellWithReuseIdentifier:@"CalendarDayCell"];
[self addSubview:self.calendarGrids];
SSCalendarFlowLayout是UICollectionViewFlowLayout一个子类。它的子类的原因是为了调试这个问题:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *unfilteredPoses = [super layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes *pose in unfilteredPoses) {
NSLog(@"%@", NSStringFromCGRect(pose.frame));
}
return unfilteredPoses;
}
有趣的是,layoutAttributesForElementsInRect的每个项目的输出是正确的,就像下面控制台输出:
2012-11-12 23:42:59.275 Calendar[49367:c07] {{0, 22}, {44, 44}}
2012-11-12 23:42:59.275 Calendar[49367:c07] {{55.2, 22}, {44, 44}}
2012-11-12 23:42:59.276 Calendar[49367:c07] {{110.4, 22}, {44, 44}}
2012-11-12 23:42:59.278 Calendar[49367:c07] {{165.6, 22}, {44, 44}}
2012-11-12 23:42:59.278 Calendar[49367:c07] {{220.8, 22}, {44, 44}}
2012-11-12 23:42:59.279 Calendar[49367:c07] {{276, 22}, {44, 44}}
2012-11-12 23:42:59.279 Calendar[49367:c07] {{0, 76}, {44, 44}}
但是为什么输出是如此不同到从UICollectionViewFlowLayout设置的框架?在模拟器和iPhone中输出都是错误的。
我怀疑这是与此相关的一个错误:http://openradar.appspot.com/12433891 但与此错误不同,UICollectionViewFlowLayout错位每一行中的单元格,而不仅仅是第一行。