2

I've worked on the Zbar in iPhone and also in iPad, it works fine without any issues, but not with the landscape mode in iPad. When I present the ZBarReaderViewController in iPad with a popover in landscape mode, the view is 90 degree shifted as in the below image,

Zbar in landscape

where the bag is on the table and the image is captured with iPad in landscape mode. I want the bag image not as shifted.

I've already tried setting the supportedOrientationsMask as

reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationLandscapeLeft || UIInterfaceOrientationLandscapeRight);

But its not showing in the correct orientation, but is a 90 degree shifted. Can someone help me solve this issue? Any timely help is much more appreciated. Thanks.

Ananth
  • 815
  • 9
  • 26

2 Answers2

3

I had almost the same issue, and I got it resolved by adding the below code. My app supports only Landscape orientation:

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIDeviceOrientationLandscapeLeft == orientation) {
    //Rotate 90
    reader.cameraViewTransform = CGAffineTransformMakeRotation (3*M_PI/2.0);
} else if (UIDeviceOrientationLandscapeRight == orientation) {
    //Rotate 270
    reader.cameraViewTransform = CGAffineTransformMakeRotation (M_PI/2.0);
}
Joe M
  • 669
  • 6
  • 9
  • should be marked as correct answer. Had the same problem and it did fix it indeed. – Maverick1st Mar 05 '13 at 13:26
  • The actual reason for this behaviour is that the UIImagePickerController, which the ZBar SDK is using for capturing the image, by default is in the Portrait orientation. – Joe M May 27 '13 at 09:49
  • +1, [self.readerView willRotateToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] duration:0] doesn't works as expected – Mykola Denysyuk Oct 09 '14 at 09:14
  • where i need to add this, which method? – Suhail kalathil Oct 15 '14 at 08:37
  • I don't remember exactly, and I don't have the code with me now. But I guess it has to be in both ViewWillAppear or ViewDidLoad and in willRotateToInterfaceOrientation – Joe M Oct 20 '14 at 08:44
1

The thing with this solution is that is fixes only the visual part of the problem. The user sees the right orientation, however the ZBarReader still 'sees' the same image, because you're transforming the preview image. What works is this:

[self.readerView willRotateToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] duration:0];

in the viewDidLoad method of your ViewController containing the ZBarReaderView.

Now_what
  • 29
  • 1
  • 3