Search code examples
iosxcodeipadzxing

zxing reader in landscape mode


I have a issue ; I have used zxing library for my iPad application; it works fine to read the qr code.

But its reader in landscape mode rotates the live feed from the camera to 90 degrees right; I want it to be without rotation just like in portrait mode where there is no rotation.

in portrait mode , the video feed is not rotated;have a look in portrait mode , the video feed is not rotated;have a look

But in Landscapemodeleft , the video feed is rotated;have a look again enter image description here


Solution

  • Zxing library uses AVFoundation framework to show live camera layer. This layer(prevLayer) is added on the ZXingWidgetController's view layer in initCapture method. So whenever you rotate your camera this layer also rotate. To keep this layer in fixed position you will need to rotate it again by 0, M_PI, -M_PI/2, M_PI/2 in portrait, upsideDown, landscapeRight, landscapeLeft using following rotation transform

    CATransform3D transform =  CATransform3DMakeRotation(angle, 0, 0, 1.0);
    self.prevLayer.transform =transform;
    self.prevLayer.frame = frame; // you may need to set it also if needed.