ZBarReaderViewController reader view changes orientation for iOS6 & iOS7 even after restricting it by _reader.supportedOrientationsMask

StackOverflow https://stackoverflow.com/questions/22111093

Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top