iPhoneアプリをUniversalにしてiPad対応した時に対応した7つの事


1. DevicesをUniversalにする

2. iPad用のアイコンを用意する

3. iPad用のスクリーンショットを用意する

必須のスクリーンショットのサイズはスクリーンショットの仕様に記載されています。

4. 横画面対応を検討する

iPadでは横画面対応をする必要があります。回避方法もありますので、対応を検討し対応します。
詳しくはiPadでDevice OrientationをPortraitのみにする方法に記載しました。

5. actionSheetの対応

UIAlertControlleractionSheet を使っている場合はiPad用の実装が必要になります。
私の場合は以下の実装を行いました。

        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

        alert.popoverPresentationController?.sourceView = view
        alert.popoverPresentationController?.sourceRect = CGRect(x: view.bounds.width - 5, y: 90, width: 0, height: 0)
        alert.popoverPresentationController?.permittedArrowDirections = .up

BarButtonItem を使っている場合は sourceRect ではなく barButtonItem を設定します。
詳しくはUIAlertControllerをiPadで使用する際の注意点にまとまっています。

6. UIActivityViewControllerの対応

UIActivityViewController を使っている場合も actionSheet と同様の対応が必要になります。
私の場合は以下の実装を行いました。

        let activityVC = UIActivityViewController(activityItems: [], applicationActivities: nil)
        activityVC.popoverPresentationController?.sourceView = view
        activityVC.popoverPresentationController?.sourceRect = CGRect(x: view.bounds.width / 2, y: view.bounds.height / 2, width: 0, height: 0)

7. UICollectionViewの対応

UICollectionViewCell のサイズを画面サイズで決める実装をしていたので対応が必要でした。
ViewControllerの viewWillTransition メソッドで画面の向きの変更を検知できるので、このメソッドをoberrideして必要な処理を実行します。
例えばこんな感じです。

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        updateCollectionViewLayout(fullWidth: size.width)
        collectionView.reloadData()
    }

    private func updateCollectionViewLayout(fullWidth: CGFloat) {
        if let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
            let space = layoutHelper.space
            flowLayout.minimumInteritemSpacing = space
            flowLayout.minimumLineSpacing = space
            flowLayout.itemSize = layoutHelper.getPhotoCellSize(fullWidth: fullWidth)
        }
    }

その他参考にしたページ