当我在横向中启动视图控制器时,单元格位于错误的位置(从左侧和右侧放置不正确),但在旋转后,一切都在纵向和横向上都能正常工作。 可以做些什么呢?我尝试使布局无效,调用旋转方法无济于事。
这是我的代码:
设置流程布局:
self.flowLayout = [[PSTCollectionViewFlowLayout alloc] init];
self.flowLayout.scrollDirection = PSTCollectionViewScrollDirectionVertical;
self.flowLayout.minimumInteritemSpacing = VERTICAL_ITEM_SPACING;
self.flowLayout.minimumLineSpacing = HORIZONTAL_ITEM_SPACING;
插入方法:
- (UIEdgeInsets)collectionView:(PSTCollectionView *)collectionView
layout:(PSTCollectionViewLayout*)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section {
self.currentOrientation = [UIApplication sharedApplication].statusBarOrientation;
self.insets = UIInterfaceOrientationIsPortrait(self.currentOrientation) ? UIEdgeInsetsMake(0, 72, 24, 72) : UIEdgeInsetsMake(0, 35, 24, 35);
//[self.collectionView.collectionViewLayout invalidateLayout];
return self.insets;
}
答案 0 :(得分:2)
子类PSTCollectionViewFlowLayout
@interface FlowLayout : PSTCollectionViewFlowLayout
在FlowLayout的init中设置所有属性
-(id)init{
self = [super init];
if (self) {
self.scrollDirection = PSTCollectionViewScrollDirectionVertical;
self.minimumInteritemSpacing = VERTICAL_ITEM_SPACING;
self.minimumLineSpacing = HORIZONTAL_ITEM_SPACING;
self.currentOrientation = [UIApplication sharedApplication].statusBarOrientation;
self.sectionInset = UIInterfaceOrientationIsPortrait(self.currentOrientation) ? UIEdgeInsetsMake(0, 72, 24, 72) : UIEdgeInsetsMake(0, 35, 24, 35);
}
return self;
}
//然后初始化您的Flowlayout
self.flowLayout = [[FlowLayout alloc] init];
//随时设备旋转重置flowlayout
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
self.collectionView.collectionViewLayout = [[FlowLayout alloc] init];
}
答案 1 :(得分:0)
我发现了一个错误,我通过单独的顶视图测量细胞的位置,这是错误的位置。细胞工作正常。