私はViewControllerに非常に単純なUICollectionViewを埋め込んでいます。UICollectionViewCellはデバイスの回転でサイズ変更を行います
UICollectionViewは、自動レイアウト(IBで定義)を使用して、ViewController内の全領域を占有します。
私のUICollectionViewCellはすべて同じサイズを持ち、ViewControllerに1つのセルしか表示されないようにするため、UICollectionView全体の領域を占めます。 UICollectionViewCellはUIImage(ズーム用のUIScrollViewに埋め込まれている)のみを表示します。
デバイスが回転する以外は正常に動作します。
のでUICollectionViewFlowLayoutの動作が定義されていない:アイテムの高さがUICollectionViewの高さよりも小さくなければなりません マイナスセクションのトップインセット値とボトム値、マイナスコンテンツのインセットは、上部と下部のエラーメッセージがあります値。 関連するUICollectionViewFlowLayoutインスタンスがあり、それが添付されています。アニメーション= {bounds.origin =; bounds.size =;位置=; };層=; contentOffset:{0、0}; contentSize:{4875、323}>コレクションビューレイアウト:。
これはかなり明確ですが、新しい高さ/幅に合わせてUICollectionViewCellのサイズを変更する必要があります。回転後、UICollectionViewCellは適切な高さ/幅で表示されますが、アニメーションは不十分です。
ここでは、コードです:
@IBOutlet weak var theCollectionView: UICollectionView!
@IBOutlet weak var theFlowLayout: UICollectionViewFlowLayout!
override func viewDidLoad() {
super.viewDidLoad()
//theCollectionView.delegate = self
theCollectionView.dataSource = self
automaticallyAdjustsScrollViewInsets = false
theFlowLayout.itemSize = theCollectionView.frame.size
theFlowLayout.sectionInset = UIEdgeInsetsMake(0,0,0,0)
theFlowLayout.minimumLineSpacing = 0.0
theCollectionView.reloadData()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
print("\(#function) \(view.frame.size)")
coordinator.animate(alongsideTransition: nil, completion: {
_ in
self.theFlowLayout.itemSize = self.theCollectionView.frame.size
})
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
print("\(#function) \(view.frame.size)")
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
print("\(#function) \(view.frame.size)")
}
質問がいつ、どのように警告を回避し、スムーズなアニメーションを取得するためにUICollectionViewCellの変更を行う、ですが? viewWillTransition(:と:)(375.0、667.0) viewWillLayoutSubviews()(667.0、375.0) viewDidLayoutSubviews()(667.0、375.0)
デバイスの回転が起こる
、私は次のように見ることができますviewDidLayoutSubviews()の直後にエラーが表示されます。 viewDidLayoutSubviews()でtheFlowLayout.invalidateLayout()を呼び出そうとしましたが、問題は変わりません。
私は最善の解決策を見つけていないが、少なくとも、それが動作し、私は他の人に同様の質問を読みましたが、私はあなたの助けを
おかげで、
セバスチャン