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

我在我的iOS应用程序中使用ZBar条码阅读器,适用于iOS 5.0或更高版本。

我已经使用Camera Interface上的以下代码隐藏了信息button。

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

但不知何故,这个代码不适用于iOS6.0及以上版本。

试试这个代码,这在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和更高版本,因为有一个额外的视图UIImageView,它应该是索引3的对象

在ZBar的最后一个版本中,我用另一个path来解决这个问题:

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

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

试试这个代码:

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

对我来说,button的path有点不同,所以这是我的解决scheme:

获取button:

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

并隐藏它:

 [cancelButton setHidden:YES]; 

或者用这个button做任何事情,我需要翻译它:

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

另一个黑客。

我不想只靠意见和子索引,很容易被改变。
所以我访问插入信息button的工具栏,并删除相应的UIBarButtonItem

创buildZBarReaderViewController的子类:

 @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])。

之前:

之前,与信息按钮

后:

之后,没有信息按钮

新设备的新解决scheme,如在iOS10中button,而不是索引3,这里是应用前解决scheme的代码。

 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]; 

希望它有帮助,问候

不是很高兴你所要求的,但要删除屏幕底部的整个酒吧,你可以使用

 reader.showsZBarControls = NO; 

这是工作代码块。

 float currentVersion = 5.1; float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; UIView * infoButton; if (sysVersion > currentVersion && sysVersion < 10 ) infoButton = [[[[[codeReader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:3]; else infoButton = [[[[[codeReader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:1]; [infoButton setHidden:YES];