如何在iOS6.0及以上版本的ZBar条形码阅读器中隐藏信息按钮

时间:2013-05-03 07:08:07

标签: iphone ios objective-c xcode zbar-sdk

我在iOS App中使用适用于iOS 5.0及以上版本的ZBar条形码阅读器。

我使用相机界面上的以下代码隐藏了信息按钮。

UIView * infoButton= infoButton = [[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:2];
[infoButton setHidden:YES];

但不知何故,此代码不适用于iOS6.0及更高版本。

8 个答案:

答案 0 :(得分:10)

试试这段代码,这对iOS5.0及以上版本起作用。

float currentVersion = 5.1;
float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue];

UIView * infoButton;
if (sysVersion > currentVersion)
   infoButton = [[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:3];
else
   infoButton = [[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:2];
[infoButton setHidden:YES];

<强>解释     在iOS 6.0中,如果您打印日志。

NSLog(@"%@",[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews]);

输出

"<_UIToolbarBackground: 0xa0991c0; frame = (0 0; 320 54); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0xa0795e0>>",
"<UIImageView: 0xa05d630; frame = (0 -3; 320 3); opaque = NO; autoresize = W+BM; userInteractionEnabled = NO; layer = <CALayer: 0xa05cfb0>>",
"<UIToolbarTextButton: 0xa0a8cc0; frame = (6 0; 60 54); opaque = NO; layer = <CALayer: 0xa0a9460>>",
"<UIButton: 0xa0960e0; frame = (290 18; 18 19); opaque = NO; layer = <CALayer: 0xa0615a0>>
iOS 5.0中的

,如果您打印日志。

NSLog(@"%@",[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews]);

输出

"<_UIToolbarBackground: 0x8d9df90; frame = (0 0; 320 54); userInteractionEnabled = NO; layer = <CALayer: 0x8dc12c0>> - (null)",
"<UIToolbarTextButton: 0x8de5ae0; frame = (6 0; 60 54); opaque = NO; layer = <CALayer: 0x8de5db0>>",
"<UIButton: 0x8d1b110; frame = (290 18; 18 19); opaque = NO; layer = <CALayer: 0x8dba2b0>>"

因此,对于iOS 6.0及更高版本,它应该是索引3处的对象,因为有一个额外的视图UIImageView

答案 1 :(得分:6)

使用最新版本的ZBar,我用另一条路径解决了这个问题:

UIView * infoButton = [[[[[reader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:3];

[infoButton setHidden:YES];

数组键更改为[2] [0] [3]

答案 2 :(得分:3)

试试这段代码:

UIView * infoButton = [[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:3];

[infoButton setHidden:YES];

答案 3 :(得分:2)

对我来说,按钮的路径有点不同,所以这是我的解决方案:

获取按钮:

UIButton *cancelButton = [[[[[reader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:2] subviews] objectAtIndex:0];

隐藏它:

[cancelButton setHidden:YES];

或者使用此按钮执行任何操作,我需要翻译它:

[cancelButton setTitle:@"キャンセル" forState:UIControlStateNormal];

答案 4 :(得分:2)

另一个黑客。

我不想仅仅依赖于视图和子视图索引,很容易被更改。
因此,我访问插入信息按钮的工具栏,并删除相应的UIBarButtonItem

创建ZBarReaderViewController的子类:

@interface ZBarReaderViewControllerWithoutInfoButton : ZBarReaderViewController

@end

@implementation ZBarReaderViewControllerWithoutInfoButton


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // Accessing the toolbar
    UIToolbar *toolbar = [[controls subviews] firstObject];

    // Only keeping the first two items of the toolbar, thus deleting the info button
    if ([toolbar isKindOfClass:UIToolbar.class]) {
        toolbar.items = @[ toolbar.items[0], toolbar.items[1] ];
    }
}

@end

在呈现扫描仪视图控制器时,不要忘记实例化这个新的子类([ZBarReaderViewControllerWithoutInfoButton new]而不是``[ZBarReaderViewController new]`)。


之前:

Before, with info button

后:

After, without info button

答案 5 :(得分:2)

新设备的新解决方案,如在iOS10中这样按下它的2而不是index3,这里是应用了之前解决方案的代码。

float currentVersion = 5.1;
float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
UIView * infoButton;

if (sysVersion > currentVersion && sysVersion < 10 )
   infoButton = [[[[[self.scanReader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:3];
else
   infoButton = [[[[[self.scanReader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:1];

[infoButton setHidden:YES];

希望它有所帮助,问候

答案 6 :(得分:1)

不完全符合您的要求,但要删除屏幕底部的整个栏,您可以使用

reader.showsZBarControls = NO;

答案 7 :(得分:0)

这是工作代码块。

IFS=$'\n' read -r -d '' -a files <url.txt || (( ${#files[@]} ))