I am working with the builtInWideAngleCamera
back main camera for iPhone.
Using the method ramp(toVideoZoomFactor:withRate:)
I am trying to create a function that smoothly transitions from zoom factor 1x to 3x over a duration of 0.25 seconds. Then in another function transition from zoom factor 3x back to 1x over a duration of 0.25 seconds.
I have tried a range of withRate
values and am getting unexpected results and very slow camera zooming.
Documentation:
(tovideozoomfactor:withrate:)
Code:
func cameraZoomIn() {
if let deviceCameraSelected = deviceCameraSelected {
do {
try deviceCameraSelected.lockForConfiguration()
try deviceCameraSelected.ramp(toVideoZoomFactor: 3, withRate: 0.25)
deviceCameraSelected.unlockForConfiguration()
} catch {
print("Error: \(error)")
}
}
}
func cameraZoomOut() {
if let deviceCameraSelected = deviceCameraSelected {
do {
try deviceCameraSelected.lockForConfiguration()
try deviceCameraSelected.ramp(toVideoZoomFactor: 1, withRate: 0.25)
deviceCameraSelected.unlockForConfiguration()
} catch {
print("Error: \(error)")
}
}
}
Questions:
1 - What is the correct withRate
value to achieve a zoom factor 1x to 3x over a duration of 0.25 seconds and a zoom factor 3x to 1x over a duration of 0.25 seconds?
2 - The documentation says the zoom transition is a visually linear transition but how can I get a transition curve that is curveEaseInOut
similar to regular UIView.animate
transitions?