我見過的所有答案都沒有回答這個問題。我試圖改變UICollectionView
的框架。記錄時會顯示框架更改,但它不會實際更改框架。我沒有設置任何約束。只是改變框架。就這樣。我正在創建一個不可滾動的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];
你是用IB還是代碼創建的?如果通過IB - 您是否設置了自動調整和自動對齊? –
使用IB創建。我沒有任何限制。不確定自動調整和自動對齊。我什麼時候可以檢查? – Anil
「沒有任何約束」您的意思是Auto Layout已禁用,或者您尚未定義任何顯式約束?如果自動佈局已啓用,則對該框架所做的任何更改都將被自動佈局覆蓋。 –