UICollectionView不是要求intrinsicContentSize [英] UICollectionView not calling intrinsicContentSize
问题描述
我有一个 UICollectionViewController
,其与随机颜色用于测试目的产生细胞。现在, UICollectionViewController
嵌入在的UIScrollView
,我希望滚动视图是相同的大小,因为它是 contentSize
。
我在 UICollectionView
的一个子类,实施 intrinsicContentSize
方法,并设置 UICollectionView
的类,在IB我的自定义类。然而 intrinsicContentSize
不会被调用。我有完全相同的设置了的UITableView
还有它完美的作品。
在这个任何想法?
- (CGSize)intrinsicContentSize {
[个体经营layoutIfNeeded]
返回CGSizeMake(UIViewNoIntrinsicMetric,self.contentSize.height);
}
我不知道为什么它的发生。这里的另一个解决这个问题。成立了 UICollectionView
对象的高度约束。然后设置其恒
等于 self.collectionView.contentSize.height
。我使用类似的方法在我的应用程序,虽然我已经得到了的UITextView
而不是 UICollectionView
。
更新:我已经找到一种方法与 intrinsicContentSize
来做到这一点:<一href=\"http://stackoverflow.com/questions/19501720/uitextview-in-uiscrollview-using-auto-layout/19501939#19501939\">UITextView在UIScrollView中使用自动布局
I have a UICollectionViewController
which generates cells with a random color for testing purposes. Now that the UICollectionViewController
is embedded in a UIScrollView
, I want the scrollView to be the same size as it's contentSize
.
I made a subclass of UICollectionView
, implemented intrinsicContentSize
method, and set the UICollectionView
's class to my custom class in IB. However intrinsicContentSize
never gets called. I have the exact same setup with an UITableView
and there it works flawlessly.
Any ideas on this?
- (CGSize)intrinsicContentSize {
[self layoutIfNeeded];
return CGSizeMake(UIViewNoIntrinsicMetric, self.contentSize.height);
}
I'm not sure why it's happening. Here's another solution to this problem. Set up a height constraint on UICollectionView
object. Then set its constant
to be equal to self.collectionView.contentSize.height
. I use a similar approach in my app, though I've got UITextView
instead of UICollectionView
.
UPDATE: I've found a way to do this with intrinsicContentSize
: UITextView in UIScrollView using auto layout
这篇关于UICollectionView不是要求intrinsicContentSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!