-
iPhone Duoに向けた優れたカメラ体験を実現
iPhone Duoの外側カメラと内側カメラを活用する方法を紹介します。「Virtual Front Camera」について解説するとともに、方向コーディネーターを使ってカメラを切り替え、iPhone Duoの開閉に応じてUIを更新する方法を見ていきます。プレビューのアスペクト比、位置、回転を扱うためのベストプラクティスを学び、シームレスな撮影体験を実現しましょう。
関連する章
- 0:00 - Introduction
- 0:31 - Meet the new front cameras
- 0:58 - Discover the virtual front camera
- 1:53 - Access each camera individually
- 2:46 - Track camera direction
- 4:03 - Create a direction coordinator
- 4:50 - Use both displays at once
- 5:38 - Work with device descriptors
- 6:17 - Handle a direction change
- 7:03 - Polish your camera preview
- 8:03 - Handle rotation
- 8:47 - Next steps
リソース
関連ビデオ
WWDC26
Tech Talks
-
このビデオを検索
こんにちは カメラソフトウェアチームの Tarunです この動画では iPhone Duoの 新しいカメラ機能について 解説し それらを活用して 優れたユーザー体験を構築する 方法をご紹介します
まずは iPhone Duoに搭載された 新しいフロントカメラについて ご紹介します
デバイスの開閉に伴う カメラの向きの変更への 対応するかについてお話しします
最後に iPhone Duoでの アプリのカメラプレビューをさらに 洗練させるためのヒントをいくつか ご紹介します
それでは iPhone Duoの新しい フロントカメラを見ていきましょう
iPhone Duoは 2つの フロントカメラを搭載した 初のiPhoneです
これらのカメラはいずれも 超広角の視野角を持つ 正方形のセンサーを採用しています デバイスの外側には 外側の超広角カメラがあります このカメラは 素晴らしい写真や 動画を撮影できます デバイスを開くと 内側の超広角カメラがあります これは iPhone初の ディスプレイ内蔵カメラです アプリでは AVFoundationを 通じてフロントカメラから のストリームを取得できます
他のiPhoneと同様に AVCaptureDeviceDiscoverySessionで フロントカメラを検出します
「position.front」を デバイス種別として「Wide」または 「Ultra Wide」と 共に指定してください iPhone Duoでこれを行うと アプリは新しい「仮想フロントカメラ」 を検出するようになります
仮想フロントカメラは 外側と内側の物理カメラを 切り替える新しい AVCaptureDeviceです
iPhone Duoを開いている ときは 仮想フロントカメラは 内側のディスプレイにある フロントカメラを使用します
カメラは自動的に 外側ディスプレイの フロントカメラに切り替わります
仮想フロントカメラは アプリにとって最適なフロントカメラを 使用します 仮想フロントカメラが カメラの切り替えを 自動的に処理します ただし カメラの方向変化に 応答することで さらに 多くの機能を活用できます iPhone Duoでは 各フロントカメラに 独自のAVCaptureDeviceタイプが 割り当てられています 外側ディスプレイの フロントカメラには 組み込みの外側超広角 デバイスタイプを使用します
組み込みの内側超広角 デバイスタイプを使用すると 内側ディスプレイのフロントカメラに アクセスできます
これらのデバイスタイプを使用すると 各カメラの全機能を 利用できます
内側超広角カメラの動画解像度は 1080p で 最大 60fps に 対応しています
外側超広角カメラは 最大 4K 解像度と 120fps に対応しています
仮想フロントカメラを アプリで使用する場合 両方の物理カメラに共通する 機能にしかアクセスできません つまり 最大解像度は 1080p 最大フレームレートは 60fpsとなります
深度情報は 個々のカメラに アクセスする場合のみ 場合にのみサポートされる 点にも注意が必要です
個々のカメラを使用する場合 ユーザーがiPhone Duoを開いたり 閉じたりした 際のカメラ切り替えは アプリ側で処理する必要があります この切り替えを管理するには 新しい AVCaptureDeviceDirectionCoordinator APIを使用してください 背景として AVCaptureDevice は 従来から「fixed position」 プロパティを提供してきました
iPhone では その値は 常に「back」または 「front」でした 内側のフロントカメラと外側の フロントカメラの両方で この値は「front」となります
しかし 画面が反対を向く iPhone Duoでは ある iPhone Duo では 状況がさらに複雑になります つまり フロントカメラが 常にユーザーの方を向いている とは限らないということです 例えば ユーザーが 内側のディスプレイを見ている一方で ストリーミングを行う 場合があります この場合 フロントカメラは ユーザーから背を向けています
外側のフロントカメラから 配信を行っている最中に デバイスを閉じる場合が あります
そのカメラが ユーザーの正面を 向くようになります 開いた状態で デバイスを反転させると 背面カメラで自撮りを 行うこともできます
これで アプリと背面カメラの 両方があなたをまっすぐ 向くことになります
アプリが常にカメラの向きを 把握できるようにするには 方向コーディネーターを 使用します 方向コーディネーターは カメラの 位置をアプリに 通知し その変化に 応じて最新情報を提供します
方向コーディネーターの 作成には 監視対象のデバイスタイプ および変更ハンドラという 3 つの要素が必要です
アプリの UIView が 外側のディスプレイにある 外側前面カメラを「前方向き」 背面カメラを「後方向き」として 背面カメラを「後方向き」 として表示します
デバイスが開かれると アプリの UIView は 内側のディスプレイに移動します
変更ハンドラが呼ばれ 外側前面と背面カメラを 後方向きのカメラとして 内側フロントカメラを 前方向きとして報告します
開いた状態でデバイスを反転させると カメラアプリを外側のディスプレイに 移動させることができます この場合 リアカメラと外側の フロントカメラの両方が 「前面向き」 のデバイスになります
iPhone Duoでは カメラアプリが両方のディスプレイを 同時に使用できます これは グループビデオ通話や 子供の写真を撮りながら 楽しい映像を見せる際に最適です
この状況では 各ディスプレイに 対して同時に2つの異なるUIViewが 存在することになります
1つは外側のディスプレイ用 もう1つは内側のディスプレイ用です ビューごとに個別の 方向コーディネーターを作成します 外側画面のコーディネーターは 背面カメラを「前方向き」 として報告し
内側画面のコーディネーターは それらを後方向きとして報告します
各コーディネーターは 自身のビューを 基準とした相対位置を報告します
カメラアプリでは SceneAccessories APIで この機能を実現できます その方法については 動画「Leverage multiple displays and scenes on iPhone Duo」 をご覧ください 方向コーディネーターは メインアクターに限定されます
方向コーディネーターの 変更ハンドラ内では AVFoundation APIを 直接使用しないでください
コーディネーターは AVCaptureDevice ではなく AVCaptureDeviceDescriptor を 提供します デバイス記述子は メインアクター安全で 送信可能なAVCaptureDeviceの 表現です
これにはAVCaptureDeviceを 作成するために 必要なすべての情報が 含まれており カメラアクターに 安全に渡すことができます
そこから AVFoundation APIを 操作することができます 変更ハンドラでは 以下の 手順を実行してください ユーザーがデバイスのカメラを 開いたり閉じたりすると 変更ハンドラが呼び出され どのカメラが前方向きになったかが アプリに通知されます
この時点で 前面カメラから のストリーミングを継続できるよう AVCaptureSession を 再設定してください プレビューのミラーリングの 判断への影響を考慮します 影響するかを考慮してください 背面カメラが前面を向いている場合は 自然な自撮り プレビューを ミラーリングしてください 最後に カメラの切り替え中に UI を更新する場合は 変更ハンドラを使用してください 方向コーディネーターは AVKit にあります コーディネーターの詳細については Apple のデベロッパ向け ドキュメントにある記事「向きに 「向きに基づいてカメラを選択する」 をご覧ください
カメラの向きの変更を 確認したところで iPhone Duoで プレビューを洗練させるための ヒントをご紹介します いくつかのヒントです 内側のディスプレイで 背面カメラの全視野角を使用して ストリーミングを行う場合 プレビューの周囲に余分な表示領域が 生まれます この余分なスペースを活用して プレビューをオフセットし 残りのスペースに コントロールを 配置することができます あるいは プレビューで 画面全体を満たすことも 可能です アプリに最適な方法を 選択できます AVCaptureVideoPreviewLayer の videoGravity プロパティを使用して レイヤーの 境界内でのプレビュー配置を 決定します 詳細については ドキュメントを ご確認ください 超広角フロントカメラから 配信する場合 正方形のセンサーを活用して 画面全体を満たすことが できます AVCaptureDevice の dynamicAspectRatio を使って 内側のディスプレイで 横向きのアスペクト比を 選択してください 正方形センサーの威力をさらに詳しく 知りたい場合は 動画 「Support the Center Stage Front Camera in your iOS app」 をご覧ください(WWDC26) アプリでの回転処理に関する 最後の注意点として 回転コーディネーターを 採用することで カメラのプレビューや写真が常に 正しい向きを保つようにしてください iPhone Duoでは アプリが ディスプレイを切り替えると 回転コーディネーターが更新されます 回転コーディネーターを 使用することで すべてのディスプレイで アプリの回転が 一貫して適用されるようにします 回転コーディネーターの 詳細については 記事「Supporting Device Rotation in Your Camera App」を ご覧ください 回転コーディネーターを採用した後は パフォーマンスを向上させるために カメラセンサーの向き 補正を無効にしてください この補正機能は iPhone Duoの 全フロントカメラで有効です 次の手順をいくつかご紹介します iPhone Duoの機能を最大限に 活用するには iOS 27.1 SDKを使用してください デバイスの開閉時に アプリがカメラの切り替えをどのように 処理するかを決定してください
仮想フロントカメラ以外の機能を 利用したい場合は 方向コーディネーターを 採用してください 最後に iPhone Duoでテストし カメラプレビューを確認します 表示を確認しましょう
iPhone Duo上で 皆様のアプリが展開されることを 楽しみにしています
-
-
3:00 - Understand AVCaptureDevicePosition
enum AVCaptureDevicePosition: Int { case unspecified case back case front } extension AVCaptureDevice { // ... var position: AVCaptureDevicePosition { get } } -
4:06 - Initialize a direction coordinator
directionCoordinator = AVCaptureDeviceDirectionCoordinator( view: view, deviceTypes: [ .builtInOuterUltraWideCamera, .builtInInnerUltraWideCamera, .builtInDualWideCamera, ], changeHandler: { [weak self] map in self?.updateCameraSession(map) } ) -
7:30 - Configure the video preview layer
class AVCaptureVideoPreviewLayer { // ... var videoGravity: AVLayerVideoGravity { get set } } -
7:51 - Select a dynamic aspect ratio
class AVCaptureDevice { // ... var dynamicAspectRatio: AVCaptureDevice.AspectRatio? { get } } -
8:34 - Disable sensor orientation compensation
// Disable for improved performance class AVCapturePhotoOutput: AVCaptureOutput { // ... var isCameraSensorOrientationCompensationEnabled: Bool { get set } }
-
-
- 0:00 - Introduction
Tarun from the camera software team introduces the new camera features on iPhone Duo: the new front cameras, handling camera direction changes when people open or close the device, and tips for polishing your app's camera preview.
- 0:31 - Meet the new front cameras
iPhone Duo is the first iPhone with two front cameras, both square sensors with an ultrawide field of view. The outer ultrawide camera sits on the outside of the device, while opening it reveals the inner ultrawide camera — the first under-display camera on iPhone.
- 0:58 - Discover the virtual front camera
Stream from the front cameras through AVFoundation, using AVCaptureDeviceDiscoverySession with position .front and the wide or ultrawide device type. On iPhone Duo this discovers the new virtual front camera, which automatically switches between the inner physical camera when open and the outer one when closed, always using the most relevant camera for your app.
- 1:53 - Access each camera individually
Each front camera has its own AVCaptureDevice type — built-in outer ultrawide and built-in inner ultrawide — giving access to each camera's full capabilities. The inner camera supports 1080p up to 60fps, the outer up to 4K and 120fps. The virtual front camera exposes only features common to both, meaning 1080p and 60fps, and depth is supported only when accessing the individual cameras.
- 2:46 - Track camera direction
When using individual cameras, your app is responsible for switching as people open or close the device — use the new AVCaptureDeviceDirectionCoordinator. AVCaptureDevice's position property has always been back or front, and both front cameras report front, but on iPhone Duo the displays can face opposite directions, so a front camera isn't always looking at you. The coordinator keeps your app up to date on where cameras are facing.
- 4:03 - Create a direction coordinator
A direction coordinator needs three things: your app's UIView, the device types to monitor, and a change handler. When your view is on the outer display, outer front cameras report as forward-facing and rear cameras as backward-facing. Opening the device moves your view to the inner display and calls your change handler, which then reports the inner front camera as forward-facing.
- 4:50 - Use both displays at once
A camera app can use both displays simultaneously — useful for a group video call, or for showing a child something fun while photographing them. With a separate UIView per display, create a separate direction coordinator for each, since each reports positions relative to its own view. Camera apps enable this with the SceneAccessories API, covered in "Leverage multiple displays and scenes on iPhone Duo".
- 5:38 - Work with device descriptors
Because the direction coordinator is tied to a view, it's isolated to the main actor, so your change handler shouldn't use AVFoundation APIs directly. Instead of an AVCaptureDevice, the coordinator provides an AVCaptureDeviceDescriptor — a main-actor-safe, sendable representation containing everything needed to create an AVCaptureDevice, which you can safely pass to your camera actor.
- 6:17 - Handle a direction change
When your change handler is called, reconfigure your AVCaptureSession to keep streaming from the forward-facing camera. Consider how the new direction affects mirroring — mirror the preview when the rear camera is forward-facing for a natural selfie experience — and perform any UI updates your app needs. The direction coordinator is found in AVKit.
- 7:03 - Polish your camera preview
Streaming the rear camera's full field of view on the inner display leaves extra space around the preview: offset the preview to group controls in the remaining space, or let it fill the display. Use videoGravity on AVCaptureVideoPreviewLayer to control layout within the layer bounds. When streaming from the ultrawide front cameras, use dynamicAspectRatio on AVCaptureDevice to select a landscape aspect ratio and fill the display.
- 8:03 - Handle rotation
Adopt AVCaptureDeviceRotationCoordinator to keep your camera preview and photos upright. On iPhone Duo it updates when your app moves between displays, so rotation is applied consistently. After adopting it, disable camera sensor orientation compensation — enabled on all iPhone Duo front cameras — to improve performance.
- 8:47 - Next steps
Use the iOS 27.1 SDK to take full advantage of iPhone Duo, decide how your app will handle switching cameras when the device opens or closes, adopt a direction coordinator if you want to move beyond the virtual front camera, and test that your camera preview looks great.