有UICollectionViewCell
包含imageView。
在集合视图上方有一个UIPageControl
图像来自照片库并显示。
加载集合视图时未确定UIPageControl
高度。
我收到以下错误:
the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
UICollectionViewController
作为子控制器添加到UIStackView
。class PhotoBrowserCell : UICollectionViewCell {
let imageView = UIImageView()
//MARK: Initializers
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
//MARK: Setup
private func setup() {
setupBaseView()
setupImageView()
}
private func setupBaseView() {
backgroundColor = UIColor.blueColor()
}
private func setupImageView() {
imageView.image = UIImage(named: "PlaceHolder")
imageView.contentMode = .ScaleAspectFit
imageView.clipsToBounds = true
imageView.setContentHuggingPriority(1000, forAxis: .Vertical)
contentView.addSubview(imageView)
imageView.translatesAutoresizingMaskIntoConstraints = false
let insets = UIEdgeInsets(top: 10, left: 20, bottom: 30, right: 20)
imageView.leadingAnchor.constraintEqualToAnchor(contentView.leadingAnchor, constant: insets.left).active = true
imageView.trailingAnchor.constraintEqualToAnchor(contentView.trailingAnchor, constant: -insets.right).active = true
imageView.topAnchor.constraintEqualToAnchor(contentView.topAnchor, constant: insets.top).active = true
imageView.bottomAnchor.constraintEqualToAnchor(contentView.bottomAnchor, constant: -insets.bottom).active = true
}
}
private func requestAssetSelected() {
let size = imageViewSize
if let assetSelected = assetSelected {
cachingManager.requestImageForAsset(assetSelected,
targetSize: size,
contentMode: .AspectFit,
options: nil) { [weak self] image, info in
//This completion handler might be called multiple times
//First time it provides a temporary image and then shows a full size image
//So ensure it is not a temporary (degraded) image
if let image = image,
isDegraded = info?[PHImageResultIsDegradedKey] as? Int where isDegraded == 0 {
self?.imagesToUpload.append(image)
self?.photoBrowser.reload()
}
}
}
else {
photoBrowser.reload()
}
}
答案 0 :(得分:2)
UIPageControl
为零。很久以后计算了UIPageControl
高度。UIPageControl
正在使用它的内在大小。这就是为什么它只是第一次发生。
添加高度约束,以便它不必依赖于它的内在高度计算:
pageControl.heightAnchor.constraintEqualToConstant(38).active = true
答案 1 :(得分:0)
==>高度错了所以设置约束....
==>此链接将帮助您解决与高度和约束相关的所有问题
https://www.youtube.com/watch?v=6KImie4ZMwk