objective-c - ZBarReaderView UIView 相机方向问题

标签 objective-c ios uiview zbar-sdk zbar

我目前正在开发一个使用 ZBarSDK 读取二维码的 iPad 应用程序。

我正在使用 ZBarReaderView(不是 UIViewController),所以我在 UIView 中显示前置摄像头,它是使用 CGRect(见下面的代码)。

我的问题是相机出现在 View 中的一侧。 iPad 应用程序将仅开发为在横向模式下工作。

UIView 现在出现时,图像在它的一侧,我不确定如何修复它。我尝试使用 CGAffineTransform 成功地稍微改变了角度,但是如果 iPad 以另一种方式翻转,这将如何处理?

我看到了一些关于这个类似问题的其他帖子,但没有对我有用的解决方案。值得注意的是我使用的是 IOS6,请记住我使用的是 ZBarReaderView,因此 supportedOrientationsMask 不可用。

我希望用户在直立位置看到相机 View ,无论横向是左侧还是右侧。不过现在,无论转向哪个方向,视频都是横向的(所以我可以看到自己与侧面成 90 度角)。 UIView 也不会在屏幕转动时发生任何变化。我有点迷路了。

代码:

- (void) viewDidAppear: (BOOL) animated {

    ZBarReaderView * readerView = [ZBarReaderView new];
    ZBarImageScanner * scanner = [ZBarImageScanner new];
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

    [readerView initWithImageScanner:scanner];
    readerView.readerDelegate = self;
    readerView.tracksSymbols = YES;

    readerView.frame = CGRectMake(20,220,230,230);
    readerView.torchMode = 0;
    readerView.device = [self frontFacingCameraIfAvailable];
    [readerView start];

    [self.view addSubview: readerView];

}

-(void)relocateReaderPopover:(UIInterfaceOrientation)toInterfaceOrientation {
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
        readerView.previewTransform = CGAffineTransformMakeRotation(M_PI_2);
    } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        readerView.previewTransform = CGAffineTransformMakeRotation(-M_PI_2);
    } else if (toInterfaceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
        readerView.previewTransform = CGAffineTransformMakeRotation(M_PI);
    } else {
        readerView.previewTransform = CGAffineTransformIdentity;
    }
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
        return YES;
    } else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        return YES;
    } else {
        return NO;
    }
}

- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) orient
                                 duration: (NSTimeInterval) duration
{
    if (orient == UIInterfaceOrientationLandscapeLeft) {
        [readerView willRotateToInterfaceOrientation: orient
                                            duration: duration];

    }
    if (orient == UIInterfaceOrientationLandscapeRight) {
        [readerView willRotateToInterfaceOrientation: orient
                                            duration: duration];

    }
}

- (BOOL)shouldAutorotate {

    UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

    if (orientation == UIInterfaceOrientationLandscapeLeft) {
        return YES;
    } else if (orientation == UIInterfaceOrientationLandscapeRight) {
        return YES;
    } else {
        return NO;
    }
}

-(NSUInteger) supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

最佳答案

我遇到了同样的问题并顺利解决了!

我只需要打电话:

[reader willRotateToInterfaceOrientation: toInterfaceOrientation duration: duration];

在包含 ZbarReaderView 的 View Controller 的 willRotate... 中。

关于objective-c - ZBarReaderView UIView 相机方向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14087736/

相关文章:

iOS: "Constants.h"错误

ios - UISearchController 中的搜索图标被截断

ios - 如何从一个文件控制所有导航栏?

iphone - 使用 Interface Builder 构建的自定义 UIView 可通过 Interface Builder 访问/定位

iphone - 从文本文件中读取 - Objective C

objective-c - NSButton setEnabled 不起作用

objective-c - CABasicAnimation 当前耗时

iphone - 超过五秒的 iphone 声音

ios - UIView/ViewController 名称【图】

ios - 如何改变 UISegmentedControl 的圆角半径?