AVCaptureVideoPreviewLayer smooth orientation rotation

后端 未结 9 921
Happy的楠姐
Happy的楠姐 2021-02-02 16:45

I\'m trying to disable any discernable orientation rotation to an AVCaptureVideoPreviewLayer while still maintaining rotation for any subviews. AVCaptureVideoPreviewLayer does h

9条回答
  •  别那么骄傲
    2021-02-02 16:48

    In swift I use:

    override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
        if !UIDevice.currentDevice().model.contains("Simulator") {
            if (toInterfaceOrientation == .Portrait) {
                prevLayer?.transform = CATransform3DMakeRotation(0, 0, 0, 1)
            } else if (toInterfaceOrientation == .LandscapeLeft) {
                prevLayer?.transform = CATransform3DMakeRotation(CGFloat(M_PI)/2, 0, 0, 1)
            } else if (toInterfaceOrientation == .LandscapeRight) {
                prevLayer?.transform = CATransform3DMakeRotation(-CGFloat(M_PI)/2, 0, 0, 1)
            }
            prevLayer?.frame = self.scanView.frame
        }
    }
    

提交回复
热议问题