カスタムキーボードの中で UICollectionView を使用している場合に、デバイスの向きが変わった後にセルのサイズを変更することができず、 landscape モードでレイアウトが崩れていた。
カスタムキーボード特有の話なのかわからないが、デバイスの向きが変わった後に - collectionView:layout:sizeForItemAtIndexPath:
は呼ばれなくなり、セルのサイズの計算が portrait モードから変わってないのが原因だった。
それが何故なのかは分からないが、向きが変わった後に下記のメソッドを呼び出すことで解決された。
collectionView.performBatchUpdates(nil, completion: nil)
挿入、削除、読み込みなどを行うときに呼ぶことで、複数のアニメーションを一括で実行できるらしい。それだけだと今回の問題に適用できるようには読めないが、リファレンスによると下記の通り use it to change the layout parameters associated with one or more cells.
とあるので、この部分が該当するのかな。
You can use this method in cases where you want to make multiple changes to the collection view in one single animated operation, as opposed to in several separate animations. You might use this method to insert, delete, reload, or move cells or use it to change the layout parameters associated with one or more cells. Use the blocked passed in the updates parameter to specify all of the operations you want to perform.