0

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?

asked Oct 17, 2023 at 10:23
2
  • Tried setting focusMode = .continuousAutoFocus ? Commented Oct 17, 2023 at 15:36
  • @RTXGamer I have tried the same but getting same results. Also I have open CV library integrated. Commented Oct 19, 2023 at 5:18

1 Answer 1

0

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.

answered Mar 29, 2024 at 7:19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.