Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 使.UICollectionViewCell的高度/宽度取决于屏幕大小_Swift_Xcode_Uicollectionview - Fatal编程技术网

Swift 使.UICollectionViewCell的高度/宽度取决于屏幕大小

Swift 使.UICollectionViewCell的高度/宽度取决于屏幕大小,swift,xcode,uicollectionview,Swift,Xcode,Uicollectionview,我在一个ViewController中有三个collectionview。如果现在设置约束,则每列的单元格数量将发生变化,这将破坏我的应用程序。有没有一种没有限制的特殊方法来处理这个问题?实现 let scW = UIScreen.main.bounds.width let scH = UIScreen.main.bounds.height func collectionView(_ collectionView: UICollectionView, la

我在一个
ViewController
中有三个
collectionview
。如果现在设置约束,则每列的单元格数量将发生变化,这将破坏我的应用程序。有没有一种没有限制的特殊方法来处理这个问题?

实现

let scW = UIScreen.main.bounds.width
let scH = UIScreen.main.bounds.height

func collectionView(_ collectionView: UICollectionView, 
                  layout collectionViewLayout: UICollectionViewLayout, 
           sizeForItemAt indexPath: IndexPath) -> CGSize {

  if collectionView == col1 {
      return CGSize(width:<##>,height:<##>) // supply ratio of screen width/height
  }
  else ...
  ...
}
让scW=UIScreen.main.bounds.width
设scH=UIScreen.main.bounds.height
func collectionView(collectionView:UICollectionView,
布局集合视图布局:UICollectionViewLayout,
sizeForItemAt indexPath:indexPath)->CGSize{
如果collectionView==col1{
返回CGSize(宽度:,高度:)//屏幕宽度/高度的提供比率
}
其他的
...
}

之后我该怎么办?再次设置约束?这将过度写入约束,因此无论如何都不需要约束啊,太好了,我看到了。现在宽度合适了。高度实际上并没有改变,即使我在代码中增加了它