I am implementing pan and zoom features for an app using a custom USB camera device, in iPadOS. I am using an update function (shown below) to apply transforms for scale and translation but they are not working. By re-enabling the animation I can see that the scale translation seems to initially take effect but then the image animates back to its original scale. This all happens in a fraction of a second but I can see it. The translation transform seems to have no effect at all. Printing out the value of AVCaptureVideoPreviewLayer.transform
before and after does show that my values have been applied.
private func updateTransform() {
#if false
// Disable default animation.
CATransaction.begin()
CATransaction.setDisableActions(true)
defer { CATransaction.commit() }
#endif
// Apply the transform.
logger.debug("\(String(describing: self.videoPreviewLayer.transform))")
let transform = CATransform3DIdentity
let translate = CATransform3DTranslate(transform, translationX, translationY, 0)
let scale = CATransform3DScale(transform, scale, scale, 1)
videoPreviewLayer.transform = CATransform3DConcat(translate, scale)
logger.debug("\(String(describing: self.videoPreviewLayer.transform))")
}
My question is this, how can I properly implement pan/zoom for an AVCaptureVideoPreviewLayer
? Or even better, if you see a problem with my current approach or understand why the transforms I am applying do not work, please share that information.