Reputation: 11
[enter image description here][1]I am trying to create an automatic zoom for my camera. However, I haven't even been getting close to figure it out. https://developer.apple.com/documentation/avfoundation/avcapturedevice/1624614-ramp I've been attempting to use this ramp function but get an error every time I try to call the function. I would just like the zoom to go from all the way "zoomed out" to all the way "zoomed in" in a 5 second time interval. Please help me understand what I need to do in order to create the function.
func autoZoom() {
let camera = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
do {
try camera?.lockForConfiguration()
camera?.videoZoomFactor = 5
camera?.ramp(toVideoZoomFactor: 1, withRate: 0.4)
} catch { }
}
Upvotes: 1
Views: 1095
Reputation: 850
The ramp is getting set to quickly, try setting a delay or use some kind of user interaction to ramp to a new zoom level. Here is an example that proves my theory.
camera?.videoZoomFactor = 5
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
camera?.ramp(toVideoZoomFactor: 1, withRate: 0.4)
})
Upvotes: 0