When you move close to an object (note: not only when zooming, but as well when just moving the phone closer), it switches to the ultra.wide camera.
I know that I can enable automatic switching by using .builtInTripleCamera. However, it does not switch automatically just because I move the camera closer to an object. I think that is the magic behind the "macro mode".
I did not find anything in the docs - how can I enable the macro mode in my own camera app?
1 Answer 1
Apple say "When the video zoom factor increases and crosses a camera’s switch-over zoom factor, this camera becomes eligible to set as the activePrimaryConstituentDevice." in this document: https://developer.apple.com/documentation/avfoundation/avcaptureprimaryconstituentdevicerestrictedswitchingbehaviorconditions
So if you want your app can switch to ultra.wide camera when move iPhone close and switch to Angle Camera when fay away, you need set you device.videoZoomFactor = device.virtualDeviceSwitchOverVideoZoomFactors.first. For iPhone 14 Pro, the value is 2.
guard let virtualDeviceSwitchOverVideoZoomFactor =
input.device.virtualDeviceSwitchOverVideoZoomFactors.first as? CGFloat else {
return
}
try? input.device.lockForConfiguration()
input.device.videoZoomFactor = virtualDeviceSwitchOverVideoZoomFactor
input.device.unlockForConfiguration()
If you write like this, you can find you App can switch camera like iPhone Native Camera App.
Comments
Explore related questions
See similar questions with these tags.
focusMode = .continuousAutoFocus?