私は次のように関数center
内のコレクションビューセルを持っていますviewWIllTransition
var center = CGPoint()
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: { (context) -> Void in
if (UIDevice.current.orientation == UIDeviceOrientation.portrait) {
if let indexPath = self.categoryCV.indexPathsForSelectedItems?.first
{
print("Portrait")
let attributes: UICollectionViewLayoutAttributes? = self.categoryCV.layoutAttributesForItem(at: indexPath)
self.center = (attributes?.center)!
print("Center: \((attributes?.center)!)")
}
}
else
{
if let indexPath = self.categoryCV.indexPathsForSelectedItems?.first
{
print("Landscape")
let attributes: UICollectionViewLayoutAttributes? = self.categoryCV.layoutAttributesForItem(at: indexPath)
self.center = (attributes?.center)!
print("Center: \((attributes?.center)!)")
}
}
})}
デバイスが回転するまで上記が実装されないことを理解しています。
しかし、 私center
はdidSelectItemAt indexpath
transition.start = self.center
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let detailViewController = self.storyboard?.instantiateViewController(withIdentifier: "TVC") as? ThirdViewController
// other code
transition.start = self.center
print("outside center: \(self.center)")
}
これは、トランジションをセルの中心から開始したいのですが、デバイスを回転させるまで viewWillTransition 関数が呼び出されないためです。それで、それが入っているものに応じていつ呼び出されるようviewWillTransition
に呼び出す方法はありますか?didSelectItemAt indexpath
cell
selected
orientation