我在 SO 上看到的所有答案似乎都没有回答这个问题。我正在尝试更改 UICollectionView 的框架。记录时会显示帧更改,但它不会物理更改帧。我没有设置任何限制。只是换个框架。就这样。我正在创建一个不可滚动的 UICollectionView

    _testStringOne = @"Test String";
    _tagOne = [_testStringOne boundingRectWithSize:CGSizeMake(242.0f, 900.0f) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:15.0f]} context:nil];

    _testStringTwo = @"Another Test String";
    _tagTwo = [_testStringTwo boundingRectWithSize:CGSizeMake(242.0f, 900.0f) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:15.0f]} context:nil];

    CGRect collectionFrame = self.collectionView.frame;
    if (_tagOne.origin.x + _tagOne.size.width + _tagTwo.origin.x + _tagTwo.size.width > 242.0f)
    {
        collectionFrame.size.height = 62.0f;
        sectionCount = 2;
        itemCount = 1;
    }
    else
    {
        collectionFrame.size.height = 31.0f;
        sectionCount = 1;
        itemCount = 2;
    }
    self.collectionView.frame = collectionFrame;
    [self.collectionView reloadData];

最佳答案

在纵向和横向之间切换时,我遇到了类似的问题。
之后工作正常
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth;

关于ios - UICollectionView 框架变化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21043586/

10-14 22:39