1

当我在横向启动视图控制器时,单元格位于错误的位置(左侧和右侧的位置不正确),但是在我旋转后,纵向和横向的一切都正常。对此可以做些什么?我尝试使布局无效,调用旋转方法无济于事。

这是我的代码:

设置流布局:

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;
}
4

2 回答 2

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];
}
于 2013-10-21T12:09:38.343 回答
0

我发现了一个错误,我正在通过单独的顶视图测量单元格的位置,这是错误的位置。细胞工作正常。

于 2013-10-21T15:36:23.487 回答