1

I am using ZBarSDK for QR Code scanning feature. I want to use this only in PORTRAIT mode only. As per the documentation I set it up with below code line:

_reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);

As expected it works well with iOS 5 but with the same code this view changes orientation for iOS 6 & 7. Is supportedOrientationsMask only works with < iOS 6? Is there any other way to force this ZBar reader camera view to work only in Portrait mode? Thanks in advance

Here more details with Code:

if(_reader) // first check `_reader` is created or not?
{
    [_reader.readerView stop]; // then stop continue scanning stream of "self.ZBarReaderVC"
    for(UIView *subViews in _reader.view.subviews) // remove all subviews
        [subViews removeFromSuperview];
    [_reader.view removeFromSuperview];
    _reader.view = nil;
}

_reader = [ZBarReaderViewController new];
_reader.readerDelegate = self;

_reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);

ZBarImageScanner *scanner = _reader.scanner;

// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
               config: ZBAR_CFG_ENABLE
                   to: 0];

[_reader.view setFrame:CGRectMake(0, _topbar.frame.size.height, self.view.bounds.size.width, self.view.bounds.size.height-_topbar.frame.size.height)];

_reader.cameraOverlayView = [self CommomOverlay];

_reader.showsZBarControls=NO;

// present and release the controller
[self presentModalViewController: _reader
                        animated: NO];

Let me know in case more details required.

Niraj
  • 1,939
  • 20
  • 29
  • Hey, is it working in portrait mode? And what is the issue with landscape mode? – chandan Mar 01 '14 at 06:50
  • I don't want the screen rotate in landscape mode and keep portrait only. For iOS 5 however i change my device orientation it keeps portrait only. It's just iOS6 and iOS7 where it allows that camera screen (_reader presented on view controller) to change orientation in landscape which is the problem and should not happen. – Niraj Mar 01 '14 at 10:18

2 Answers2

3

Finally found the solution. The problem was like this: ZbarViewController *reader was presented from my current view controller and it's portrait support property was not working somehow.

_reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);

What i did to resolve this issue is I created TBZbarViewController the new class which was inheriting the ZbarViewController class and placed the below method.

-(BOOL)shouldAutorotate{
return NO;

}

Then I used the TBZbarViewController *reader to present from My controller which solved the issue and it's working in Portrait mode only as needed.

Thanks.

Niraj
  • 1,939
  • 20
  • 29
0

I did like this, and is working for all iOS versions :

Step 1 : Set your Device Orientation

enter image description here

Step 2 : Add this code into you implementation (.m) file.

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0

- (BOOL) shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

    return UIInterfaceOrientationMaskPortrait;

}

#endif

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
Ajay Sharma
  • 4,509
  • 3
  • 32
  • 59
  • Thanks Ajay, but the issue here is my app is Universal app and I have done same as mentioned you above. Thus all view controllers works well with Portrait mode but when I present ZBarReaderViewController *reader from my view controller camera reader opens up and that changes orientation which i want to block as portrait only. I don't have access to see ZBarReaderViewController.m file to make any change. But strange that below line is not working. _reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait); Any insight on this? – Niraj Mar 01 '14 at 14:23