How to detect iPhone device flattened usig camera

44 Views Asked by At

I am trying to detect the device flattened to the surface to take pictures like the native camera. Like below Screenshot Native camera

I tried using CMMotionManager,

      let motioManager = CMMotionManager()
       motioManager.deviceMotionUpdateInterval = 0.2
         
        if (motioManager.isAccelerometerAvailable){
            motioManager.startAccelerometerUpdates(
                to: OperationQueue.current!,
                withHandler: {(accelData: CMAccelerometerData?, errorOC: Error?) in
                    self.outputAccelData(acceleration: accelData!.acceleration)
                })
        }
    
        if  acceleration.x > -0.1 && acceleration.x > -0.1   {
            
            if  acceleration.y < 0.1 && acceleration.y < 0.1 {
 
                UIView.animate(withDuration: 0.05, delay: 0, options: .curveEaseIn) {
                    
                    self.centerLabel.frame.origin.x = self.screen.midX-20
                    self.centerLabel.frame.origin.y = self.screen.midY-20
                } completion: { [self] done in

}
                    

But I am not getting a smooth output. Could anyone help me out with how to achieve this? Thanks in advance Out put view

0

There are 0 best solutions below