我在我的iOS应用使用zbar和条形码阅读器适用于iOS 5.0及以上。
我已经使用上的摄像头接口下面的代码隐藏信息按钮。
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及以上应该是在指数3的对象,因为有一个额外视图的UIImageView。
随着zbar和上一个版本的我solded这个问题,另一条路径:
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];
对我来说,路径按钮有点不同的,所以这里是我的解决方案:
获取按钮:
UIButton *cancelButton = [[[[[reader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:2] subviews] objectAtIndex:0];
而隐藏:
[cancelButton setHidden:YES];
或做任何与此按钮,我需要它翻译:
[cancelButton setTitle:@"キャンセル" forState:UIControlStateNormal];
另一个黑客。
我不想只依靠的意见和子视图索引,很容易被改变。
所以,我在那里访问信息按钮插入工具栏,并删除相应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新]`)呈现扫描器视图控制器时。
之前:
后:
在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];
希望它能帮助,问候
不excatly你问什么,但你可以使用屏幕底部删除整个酒吧
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];