Tap-to-focus (Beta)

If you have a use-case where users should be able to tap on the screen to lock the camera focus on certain objects, you can use tap-to-focus feature provided by 100ms iOS SDK.

Minimum Requirements

  • SDK version 0.4.7

What is Tap to Focus?

If you have used native iOS camera app, you know that you can tap on the camera preview screen to lock focus on certain object in the camera scene. The focus plane of the camera is set to the depth of the object in focus. This is called 'Tap to focus'.

What are different camera focus modes

There are mainly 3 focus modes:

1. AutoFocus

The default focus mode where camera continuously sets focus and exposure based on center point of the scene.

2. TapToAutoFocus

This allows user to tap to focus on an object. Once user moves the camera enough to change the subject of the scene the camera switches to default Autofocus mode

3.TapToLockFocus

This allows user to tap to lock focus on an object. The focus will not be changed until user taps again to focus on another object.

By default iOS camera uses autofocus mode. That means it constantly tries to focus on the center object in the camera scene.

How to enable Tap-to-focus mode

To enable 'Tap-to-focus' mode, you pass one of the two tap-to-focus modes (HMSCameraFocusMode) as a param to the HMSVideoSettings like below:

sdk.trackSettings = HMSTrackSettings.build { videoSettingsBuilder, audioSettingsBuilder in videoSettingsBuilder.cameraFocusMode = .focusModeTapToAutoFocus ... }

OR

sdk.trackSettings = HMSTrackSettings.build { videoSettingsBuilder, audioSettingsBuilder in videoSettingsBuilder.cameraFocusMode = .focusModeTapToLockFocus ... }

That's all you need to do. These camera modes are integrated into the HMSVideoView that you use to create video tiles. Now whenever user taps on the local camera view (HMSVideoView), the tapped object in the camera scene gets focused according to the focus mode that has been set.

HMSCameraFocusMode has following 3 modes:

  1. kHMSFocusModeAuto
  2. kHMSFocusModeTapToAutoFocus
  3. kHMSFocusModeTapToLockFocus

If you don't use cameraFocusMode video setting, the autofocus mode is used by default.

👀 To see an example iOS tap to focus implementation using 100ms SDK, checkout our example project.


Have a suggestion? Recommend changes ->

Was this helpful?

1234