當我在橫向上啓動視圖控制器時,單元格出現在錯誤的位置(從左側和右側放置的位置不正確),但在旋轉後,所有工作均可在縱向和橫向上均正常工作。 可以做些什麼呢?我試圖使佈局無效,調用旋轉方法無濟於事。UICollectionView橫向模式下的邊緣插入不正確
這裏是我的代碼:
設置流佈局:
的插圖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;
}
這是唯一可行的方法。無論您使用'sectionInset'屬性還是'collectionView:layout:insetForSectionAtIndex:'委託方法,當您使佈局無效時,部分插頁都不會更新。我向Apple提交了一個[bug報告](http://openradar.appspot.com/radar?id=5255754231578624)。 – phatmann