-
UIKitアプリのモダナイズ
UIKitの最新アップデートを確認しましょう。iPhoneミラーリングやiPadでサイズを変更した際にも最適に動作するよう、iPhoneアプリのレイアウトをアップデートする方法を解説します。タブバーやナビゲーションバーのための新しいAPI、Apple Intelligenceを活用する新機能をサポートするための準備方法、自身の好みのコーディングエージェントでコードベースをモダナイズする際に役立つスキルも紹介します。
関連する章
- 0:00 - Introduction
- 0:34 - App adaptivity
- 2:10 - Legacy API: App lifecycle
- 2:51 - Legacy API: Main screen
- 5:46 - Full-screen mode for games
- 6:17 - Legacy API: User interface idiom
- 6:50 - Legacy API: Interface orientation
- 7:55 - UIView Body protocols for motion & location
- 8:19 - Test your resizable iPhone app
- 9:18 - Tab bars and sidebars
- 10:52 - Navigation bars
- 12:37 - Menus
- 13:01 - Integrate with Apple Intelligence
- 14:07 - Agentic coding
- 15:32 - Next steps
リソース
- TN3208: Preparing your app’s launch screen to meet App Store requirements
- TN3210: Optimizing your app for iPhone Mirroring
- Make your UIKit app more flexible
- Adapting your app when traits change
- Transitioning to the UIKit scene-based life cycle
- Automatic trait tracking
- Human Interface Guidelines: Menus
関連ビデオ
WWDC26
WWDC25
WWDC24
-
このビデオを検索
こんにちは。UI Frameworksチームの Engineeringマネージャー、Michael Ochsです。
本日はUIKitアプリを モダナイズする方法をお伝えします。 このビデオでは、アプリのアダプティビティ要件に 関する大きな変更と iPhoneアプリが完全に リサイズ可能になった仕組みを説明します。 次に、タブバー、ナビゲーションバー、 メニューの新しいAPIを紹介します。 その後、Apple Intelligenceのサポート方法と 注目すべき変更点についてお話しします。
最後に、エージェントがこのモダナイズ作業の 大部分を自動的に処理する 新しいスキルについて説明します。
アプリのアダプティビティから始めましょう。 アプリはすでに さまざまな環境で動作できます。 画面サイズはさまざまで、アプリは 並べて実行することも 他のアプリや自身と同時に 動作することもできます。 iPadではアプリのリサイズや外部ディスプレイ へのシームレスな移動が期待されます。 iPhoneでは、縦向きと横向き 両方での動作が期待されます。 また、iPhoneを Macにミラーリングすることも期待されます。 iOS と macOS 27では このエクスペリエンスが改善され これらの環境で動作するアプリは 新たに公開されるようになりました プラットフォームネイティブのアプリが 対応すべき多くの動的変化に対応するためです。
MacでiPhone Mirroringを使用すると iPhoneウィンドウを完全にリサイズでき アプリのリサイズと適応が可能になります。 同様に、iPadで動作するiPhoneのみのアプリも 完全にリサイズ可能になります 他のiPadアプリと同様に。 そのため、アプリが実行時に 利用可能なシーンサイズへ 動的に調整することが重要です。 アプリがユニバーサルバイナリであれば 好スタートです。 ただし、アプリを完全にアダプティブにし 実行環境に動的に対応させるには さらに作業が必要です。 アプリをよりアダプティブにする際に 対処すべき最重要ステップと よくある問題を説明します。 アプリがapp lifecycleを 使用していないことの確認 代わりにscene lifecycle(アダプティブ アプリの基盤)を採用しているかどうかの確認 アプリがmain screenを 参照していないことの確認 user interface idiomと interface orientationの確認方法です。
最初のステップは、app lifecycleから scene lifecycleへの移行です。 ほとんどのアプリは すでにscene lifecycleを使用しています。 これはアダプティブアプリの基盤であり このビデオで紹介する他の多くのタスクの 前提条件でもあります。 UIScene lifecycleは、最新SDKでビルド する際必須になりました。 これがなければ アプリは起動しなくなります。 アプリがUISceneDelegateを 使用していることを確認してください これはscene lifecycleの基盤です。
まだscene lifecycleに移行していない場合は ビデオをご覧ください WWDC25の "Make your UIKit app more flexible"と "Transitioning to the UIKit scene-based lifecycle" (ドキュメント)を参照してください。 次に、iPhoneアプリが Macでミラーリングされているとき またはアプリがiPadの 外部ディスプレイに移動されたとき シーンに関連付けられた スクリーンが変わります。 つまり、コード内のmain screenへの 参照は正しくない情報を提供することになります アプリが実行されている 環境とは異なる情報を。 アプリでmain screenを 参照しないことが重要です。 代わりに、ウィンドウのwindow sceneから 動的にスクリーンにアクセスしてください。 即時コンテキストでviewや view controllerが使えない場合は 必要なメソッドに スクリーン参照を渡してください。 正しいスクリーンを取得するよりも スクリーン参照を完全に削除する方が効果的です。 アダプティブアプリに適した 他のAPIが多数あります。 よくある2つのパターンを 紹介します。 スクリーンのスケールへのアクセスは trait collectionのdisplayScaleで 置き換えてください。 ViewとView controllerはtrait collectionを 自動的に更新し 適切なフォールバックを提供します 表示階層に含まれていない 場合でも。 多くの共通オーバーライドポイントも トラッキングされます つまり、変更を明示的に 監視する必要はありません。 システムが使用中のtrait collection プロパティをトラッキングし layoutSubviews、updateProperties、 drawRectなどの共通レイアウトや 描画メソッド内での使用を検出します。 トラッキングされたtraitへの変更が検出されると システムはこれらのメソッドを 再度呼び出し、UIが 自動的に更新されます。 詳細は"Automatic trait tracking" (ドキュメント)をご覧ください。 自動trait trackingが使えない場合は registerForTraitChangesを使って 変更を監視できます。 このメソッドを使うと、特定のtraitが 変化したときに呼ばれる クロージャを設定できます。 これを利用してキャッシュを無効化したり そのviewに関連するデータを更新したりできます。 詳細は"Adapting your app when traits change" (ドキュメント)をご覧ください。 スクリーンのもう一つの一般的な用途は boundsを確認して アプリが使える領域を 取得することです。 しかし、アダプティブ環境では シーンが使えるスペースは 常にフルスクリーンとは限りません。 アプリにまだscreen boundsへの 参照が残っている場合は 今すぐ削除してください。 window sceneのeffective geometryは アプリが使えるスペースを 提供します。 effective geometryの変更を監視する 必要がある場合は scene delegateに windowScene:didUpdateEffectiveGeometry: を実装してください。 viewとview controllerでは scene boundsを参照する代わりに view controllerのviewまたは superviewの利用可能なサイズを使って 使えるスペースを 判断してください。
これにより、UIの表示方法への 依存度が下がります。 view controllerが他のコンテキストで 表示された場合でも適切に調整されます 例えば、split view controller内でも。 ゲームでは、リサイズは 難しい場合があります。 このため、UIRequiresFullscreenは iPhoneのリサイズ可能な環境で iOS 27からサポートされます。 動作も更新され アプリのリサイズを 完全に無効にするのではなく サポートするinterface orientationに沿った 離散的なリサイズを有効にします。
サポートするinterface orientationを尊重します。 離散的なリサイズでは、シーンサイズを 変更するたびに システムはシーンを 新しい画面構成に移行させ そのサイズに合わせます これにより、ゲームは使えるスペースで 常に最高品質でレンダリングされます。 アプリがUser Interface idiom traitを 使用している場合 このtraitはレイアウト判断において もはや意味を持たないことに注意してください。 アプリは追加スペースを 意味のある方法で活用することが求められます phoneまたはpad user interface idiomで 実行されているかどうかに関わらず。 iPhoneアプリがiPadまたはMacの iPhone Mirroringで実行されているとき 完全にリサイズ可能になりますが phone user interface idiomの下で 引き続き実行されます。 コードのレイアウト判断において user interface idiomのチェックを止めてください。
代わりにsize classを使って、メニューの 折りたたみなどのサイズ制約を処理し 利用可能なスペースに合わせて アプリのレイアウトを更新してください。 より細かい制御が必要な場合は 周囲のviewのサイズを使ってください 先ほど述べたとおりです。 Interface orientationも レイアウト判断には使えなくなりました。 iOS 27では、アプリが サポートするinterface orientation はシステムへの要望として 提供されます。 リサイズ可能な環境でアプリが 実行される場合は無視されます。 レイアウト計算においてinterface orientationを考慮すべきではありません。 MacのiPhone Mirroringでは アプリは常に 縦向きのinterface orientationで 実行されます アプリのシーンの アスペクト比に関わらず。 アプリのinterface orientationの確認も size classを使うように更新してください。 この概念的な転換は iOS 8で導入されました。
WWDC2014でBruce Niloは こう言いました。 「デバイスの回転は アニメーション付きのbounds変更にすぎない」 さまざまなデバイスサイズ、iPadの リサイズ可能ウィンドウ Macのリサイズ可能なiPhoneアプリにより この洞察は今や かつてないほど重要です。 interface orientationといえば iOS 27でUIViewも新しい CoreMotionとCorLocationの BodyプロトコルにConformしました。
これによりモーションとロケーション マネージャーの設定が格段に簡単になります。 モーションデータを可視化する viewに接続できます コンパスやマップビューなど。 これにより、データは常に 正しい座標空間に保たれます interface orientationに関わらず。 以上が主なアダプティビティの 変更点です。 次に、これらの変更を アプリでテストする方法を紹介します。 Xcode 27では、さまざまな画面サイズで アプリの動作を繰り返しテストする 新しい方法が追加されました 複数のシミュレータや デバイスにインストールすることなく。
新しいDevice Hubアプリと Xcode Previewsで アイコンを クリックしてください。 次に、デバイスの端を ドラッグして自由にリサイズします。 これにより、変更をより 素早く繰り返しテストできます。 結果に満足したら iPhone Mirroringのテストも行い 実際のデバイスでiPadも確認してください。
Device Hubアプリとそのツールについて 詳しくは "Get the most out of Device Hub"を ご覧ください。 以上がアダプティビティの説明です。 アプリを完全にアダプティブにするための 作業を支援する新しいエージェンティック コーディングスキルを紹介する前に もう2つのトピックがあります。 まず、バーとメニューです。 iPadでは、タブバーは フルサイドバー表示に展開し アプリ階層のより多くの セクションを表示できます 現在の環境がサイドバーを サポートしている場合。 iPhoneでは、下部のタブバーが デフォルトですべてのサイズで表示されます。
iOS 27の新機能として、iPhoneアプリも サイドバーを選択できるようになりました tab bar controllerの sidebar.preferredPlacementを .sidebarに設定することで。 iPadとは対照的に これはアプリの選択であることに注意してください。 アプリがサイドバー表示を 選択した場合、UIで サイドバーとタブバーの レイアウトを切り替える方法はありません。 代わりに、システムがサイドバーを 表示できる十分なスペースがあるかどうかを判断します 例えばhorizontal size classが regularの場合などです。
タブバーのサイドバー表示が 可能かどうかを判断するには sidebarのisAvailableプロパティを 使用してください。 サイドバーが現在使用できない場合は ネストされたタブの背後にあるUIを アプリの他の部分で表示してください。 タブグループの管理について 詳しくは WWDC25の"Make your UIKit app more flexible" タブバーとサイドバーとの 統合について詳しくは WWDC24の"Elevate your tab and sidebar experience in iPadOS"をご覧ください。
UITabBarControllerでは 目立つタブのカスタマイズも可能です。 目立つタブは常に表示されます スクロール中にタブバーが 折りたたまれても。 iOS 27では、prominentTabIdentifierを 設定することで 任意のタブを目立つように できます。 以上がタブバーの説明です。 次にナビゲーションバーについて説明します。
ナビゲーションバーは、スクロール中に インタラクティブにスライドアウトします。 これにより、アプリのコンテンツの 表示領域が広がります。 デフォルトでは、ナビゲーションバーは システムが定める条件下で最小化されます。
この動作はどちらの方向にも 強制できます navigation itemの barMinimizationBehaviorプロパティを .alwaysまたは.neverに 設定することで。 safe areaの回避を 自分で処理する場合は barMinimizationSafeAreaAdjustmentを .neverに設定して、バーの最小化が インセットを自動更新しないように してください。
スクロールインタラクション中の もう一つの変更は スクロールエッジエフェクトの 外観の更新です。 そのため、デザインを見直してください 特にOSが提供するデフォルトを 以前にオーバーライドした箇所を。 OSが提供するデフォルトを オーバーライドしている場合。 特に.automaticスタイルは 既存のsoftとhardスタイルの 既存のsoftスタイルと hardスタイルを切り替えるのではなく より明確さを高める独自の ビジュアルを提供するようになりました。 以前に.automaticからスタイルを オーバーライドした場合 その決定を再評価してください 特に.softに設定している場合は デフォルトのシステム外観と 一致しなくなっているためです。
Liquid Glassの洗練された 外観により メニュー要素に設定した画像は 一部のコンテキストでは デフォルトで表示されない場合があります iPadOSとmacOSの メニューバーなど。
画像を引き続き表示する必要がある場合は preferredImageVisibilityプロパティを設定して デフォルトのシステム動作を オーバーライドしてください。 更新されたHuman Interface Guidelines でメニュー要素に画像を表示する タイミングを確認してください。 以上がバーとメニューの説明です。 次に、アプリでApple Intelligenceを サポートする方法を説明します。
iOS 27のメニューには ボタンが追加され アプリから直接Siriとの 会話を始められるようになりました。 これは強力なエントリーポイントであり ユーザーが関心のあるコンテキストで インタラクションできるようにします。
Siriに関連するコンテンツがある場合 メニューはこの項目を自動的に表示します。 アプリ固有のより関連性の高い 情報を提供するには 新しいView Annotations APIを 使用してください。 これを使うと特定のviewに AppEntitiesを注釈付けできます。 詳細は "Explore advanced App Intents features for Siri and Apple Intelligence" をご覧ください。
アプリがドラッグアンドドロップを サポートしている場合 Siriはアプリの ドラッグハンドラーから リソースを読み込めます。 コンテキストメニューからApple Intelligenceが 呼び出されると、システムは 使用可能なドラッグデリゲートメソッドを 呼び出してコンテンツを読み込みます。 sessionWillBeginからのアニメーションや モーダルUIの表示は避けてください。 ドラッグセッションはユーザーの ジェスチャーなしに開始されることがあります。 ユーザーがドラッグを開始したときに 表示されるステートフルUIがある場合は そのコードをsessionDidMoveに 移してください。
説明したアダプティビティの変更が 多く感じられるかもしれませんが、ご安心ください。 今注目のエージェンティックコーディングについて 話しましょう。
Xcode 27の新機能として アプリモダナイゼーションスキルが追加されました。 先ほど説明したアダプティビティタスクを 深く理解しています。 プロジェクトのコンテキストと組み合わせることで これらの変更の多くを 自動的に行えます。 Xcodeのインテリジェンス機能を使いエージェントに アプリをよりアダプティブにするよう依頼できます main screenの呼び出しをtraitCollectionや scene boundsのチェックに 自動変換します 必要に応じて無効化ロジックも 追加します。 interface orientationのチェックを size classのチェックに置き換えます。 アプリをscene lifecycleに 変換することもできます。 より複雑なタスクでは 明確化のための質問をします。 1つのセッションで対処しきれない 大きなタスクの場合は 残りの作業を 把握しやすいよう コメントを追加します。
他のツールでスキルを使用するには Xcodeが使用するスキルを "xcrun agent skills export"で エクスポートできます。 これによりMarkdownファイルが作成され ワークフローにインポートできます。 このようなスキルは リサイズ可能な環境に向けて アプリを準備する強力な手段です。
以上です。 アプリをモダナイズするための 最重要事項を説明しました。
iOS 27 SDKでアプリをビルドしリサイズ可能 なシミュレータを試してみてください 新しいDevice Hubアプリで macOS 27のiPhone Mirroringで アプリをテストしてください。 もう少し柔軟性が必要な アプリの箇所を見つけてください。 エージェンティックコーディングが好きなら 新しいスキルをぜひお試しください どれだけ多くの作業が 自動化されるかを体験できます。 ご参加ありがとうございました。 皆さんのアプリのリサイズが楽しみです。
-
-
3:24 - Use local screen references
// Use local screen references // Access the correct screen through a windowScene let screen = window?.windowScene?.screen // Pass in local screen references func generateThumbnail(_ image: UIImage, screen: UIScreen) -> UIImage { // existing code, replacing main screen with local screen reference // ... } -
3:49 - Replace screen scale with displayScale
// Replace the screen's scale with trait collection's displayScale override func layoutSubviews() { super.layoutSubviews() // layoutSubviews will be called again automatically when displayScale changes let displayScale = traitCollection.displayScale // ... } -
4:36 - Register for trait changes
// Manually register for trait changes let displayScaleTrait: [UITrait] = [UITraitDisplayScale.self] registerForTraitChanges(displayScaleTrait) { (view: GalleryView, previousTraitCollection: UITraitCollection) in view.cache.invalidate() } -
5:19 - Monitor effective geometry changes
// UIWindowSceneDelegate func windowScene( _ windowScene: UIWindowScene, didUpdateEffectiveGeometry previousEffectiveGeometry: UIWindowScene.Geometry ) { let geometry = windowScene.effectiveGeometry let availableSpace = geometry.coordinateSpace.bounds // ... } -
5:35 - Check available space using view bounds
// Checking available space override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() let availableSpace = view.bounds.size // ... } -
8:12 - Configure motion and location body
// Configure motion and heading bodies override func viewDidLoad() { super.viewDidLoad() motionManager.deviceMotionBody = view locationManager.headingBody = view } -
9:51 - Opt into sidebar layout
tabBarController.sidebar.preferredPlacement = .sidebar -
10:22 - Check sidebar availability
tabBarController.sidebar.isAvailable -
10:53 - Set prominent tab identifier
// Set the prominent tab let tabs = [ // ... ] let tabBarController = UITabBarController(tabs: tabs) tabBarController.prominentTabIdentifier = "cart" -
11:30 - Customize bar minimization behavior
// Customize bar minimization behavior override init( nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle? ) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) navigationItem.barMinimizationBehavior = .always navigationItem.barMinimizationSafeAreaAdjustment = .never } -
15:05 - Export Xcode skills for use in other tools
xcrun agent skills export
-
-
- 0:00 - Introduction
A modern UIKit app dynamically adjusts to the environment it runs in. iOS 27 introduces new requirements and APIs to help you get there. Discover new APIs in tab bars, navigation bars, and menus; Apple Intelligence support; and a new skill that helps an agent handle much of this modernization work automatically.
- 0:34 - App adaptivity
iPhone apps are now fully resizable in iPhone Mirroring on Mac and when running on iPad. Your app needs to dynamically adjust to any available scene size at runtime. The four areas to audit are scene lifecycle adoption, main screen references, user interface idiom checks, and interface orientation checks.
- 2:10 - Legacy API: App lifecycle
UIScene lifecycle is now required when building with the latest SDKs; apps without it will no longer launch. If you haven't migrated from app lifecycle yet, start here.
- 2:51 - Legacy API: Main screen
UIScreen.main always refers to the device's main screen, but in resizable environments your scene may be running on a different screen entirely. Replace it with screen references from the window scene, trait collections for scale, and effective geometry for available space.
- 5:46 - Full-screen mode for games
UIRequiresFullscreen is now honored on iPhone in resizable environments, enabling discrete resizing that respects your supported interface orientations so games always render at full quality.
- 6:17 - Legacy API: User interface idiom
The user interface idiom trait is no longer meaningful for layout. An iPhone app running on iPad stays in the phone idiom but is fully resizable. Use size classes instead.
- 6:50 - Legacy API: Interface orientation
Supported interface orientations are treated as a preference only and are ignored in resizable environments, including iPhone Mirroring which always reports portrait. Replace orientation checks with size classes.
- 7:55 - UIView Body protocols for motion & location
UIView now conforms to the new Body protocols from CoreMotion and CoreLocation in iOS 27, making it straightforward to keep motion and location data in the correct coordinate space regardless of interface orientation.
- 8:19 - Test your resizable iPhone app
Xcode 27's Device Hub app and Xcode Previews let you freely drag the edges of the simulator to test any screen size without needing multiple devices. Test with real devices for iPhone Mirroring and iPad.
- 9:18 - Tab bars and sidebars
iPhone apps can now opt into a sidebar layout by setting tabBarController.sidebar.preferredPlacement to .sidebar, with the system deciding when there's enough space to show it. Check tabBarController.sidebar.isAvailable to determine if the system can show the sidebar, and use tabBarController.prominentTabIdentifier to pin any tab so it stays visible even when the tab bar collapses during scroll.
- 10:52 - Navigation bars
Navigation bars can now slide away during scroll to give people more room. The system determines when this happens by default; override it with barMinimizationBehavior. The .automatic scroll edge effect style has new visuals; apps that previously overrode it to .soft should re-evaluate their design.
- 12:37 - Menus
Menu element images may no longer appear by default in some contexts like menu bars on iPadOS and macOS. Use preferredImageVisibility to override this behavior where needed.
- 13:01 - Integrate with Apple Intelligence
Menus automatically display an Ask Siri button when there's content relevant for Siri. If your app supports drag and drop, Siri can load resources from your drag handlers. Drag sessions can be initiated without a user gesture, so avoid triggering animations or presenting modal UI from sessionWillBegin.
- 14:07 - Agentic coding
Xcode 27's app modernization skill can automatically convert mainScreen calls, replace orientation checks with size class checks, and migrate your app to scene lifecycle. Skills can also be exported for use in other tools.
- 15:32 - Next steps
Build with the iOS 27 SDK, test in Device Hub and iPhone Mirroring on macOS 27, identify flexibility gaps in your app, and try the agentic modernization skill.