在新设备定向后处理插入

时间:2014-07-16 15:06:16

标签: ios objective-c uicollectionview

我正在使我的iPhone应用程序具有普遍性,并且反复出现问题。我为iPad界面启用了不同的方向。我有UICollectionView个不同的单元格。我用方法计算位置和插入,以便细胞居中。

更改设备的方向时,会显示错误,我的单元格会消失,或者有时它们仍然存在。所以我不知道。

错误:

the behavior of the UICollectionViewFlowLayout is not defined because:
the item width must be less that the width of the UICollectionView minus the section insets left and right values.

尝试添加方向的观察者,当设备方向发生变化时,请调用CollectionView的reloadData。但这仍然不起作用。

计算我的收藏视图的插图:

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {

    float aantalSecties;
    int cellWidth = [self welkeAfmetingen];
    NSInteger numberOfCells;
    UIEdgeInsets insetReturn;
    NSInteger edgeInsets;
    NSInteger heightInsets;

    if([arrayDobbel count] <= 2){
        aantalSecties = 2;
    }else{
        aantalSecties = ceilf((float)[arrayDobbel count] / 2);
    }

    if (((aantalSecties - 1) == section && [arrayDobbel count] % 2) || ([arrayDobbel count] <= 2)) {
        numberOfCells = 1;

        edgeInsets = (self.view.frame.size.width - (numberOfCells * cellWidth)) / (numberOfCells + 1);

        if ([arrayDobbel count] == 1) {
            heightInsets = (self.view.frame.size.height - cellWidth) / 2;
        }else{
            heightInsets = ((self.view.frame.size.height - (aantalSecties * cellWidth)) / aantalSecties) / aantalSecties;
        }

        insetReturn = UIEdgeInsetsMake(heightInsets, edgeInsets, heightInsets, edgeInsets);
    }else{
        numberOfCells = 2;

        edgeInsets = (self.view.frame.size.width - (numberOfCells * cellWidth)) / (numberOfCells + 1);
        heightInsets = ((self.view.frame.size.height - (aantalSecties * cellWidth)) / aantalSecties) / aantalSecties;
        insetReturn = UIEdgeInsetsMake(heightInsets, edgeInsets, heightInsets, edgeInsets);

    }
    return insetReturn;
}

(行/部分上的2个单元格,如果最后一个部分中有1个单元格处于右中心位置,则处理它)

任何想法?

0 个答案:

没有答案