[英]How to hide info button in ZBar Bar Code Reader for iOS6.0 and above
I am using ZBar Bar Code Reader for iOS 5.0 and above in my iOS App. 我在我的iOS应用程序中使用适用于iOS 5.0及更高版本的ZBar条形码阅读器。
I have made info button hidden using following code on Camera Interface. 我使用Camera Interface上的以下代码隐藏了信息按钮。
UIView * infoButton= infoButton = [[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:2];
[infoButton setHidden:YES];
But somehow this code doesn't work for iOS6.0 and Above. 但不知何故,此代码不适用于iOS6.0及更高版本。
Try this code, this worked for me on iOS5.0 and above. 试试这个代码,这对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];
Explanation. 说明。 In iOS 6.0, If you print the log.
在iOS 6.0中,如果您打印日志。
NSLog(@"%@",[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews]);
Output. 输出。
"<_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>>
in iOS 5.0, If you print the log. 在iOS 5.0中,如果您打印日志。
NSLog(@"%@",[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews]);
Output. 输出。
"<_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>>"
Hence for iOS 6.0 and above it should be object at index 3 since there is an extra view UIImageView . 因此,对于iOS 6.0及更高版本,它应该是索引3处的对象,因为有一个额外的视图UIImageView 。
With the last version of ZBar I solded this problem with another path: 使用最新版本的ZBar,我用另一条路径解决了这个问题:
UIView * infoButton = [[[[[reader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:3];
[infoButton setHidden:YES];
The array keys are changed to [2] [0] [3] 数组键更改为[2] [0] [3]
Try this code : 试试这段代码:
UIView * infoButton = [[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:3];
[infoButton setHidden:YES];
For me, the path to the button was a bit different, so here is my solution : 对我来说,按钮的路径有点不同,所以这是我的解决方案:
Get the button : 获取按钮:
UIButton *cancelButton = [[[[[reader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:2] subviews] objectAtIndex:0];
And hide it : 并隐藏它:
[cancelButton setHidden:YES];
Or do whatever with this button, I needed to translate it : 或者使用此按钮执行任何操作,我需要翻译它:
[cancelButton setTitle:@"キャンセル" forState:UIControlStateNormal];
Another hack. 另一个黑客。
I didn't want to rely on only the views and subviews index, very prone to be changed. 我不想只依赖于视图和子视图索引,很容易被改变。
So I access the toolbar where the info button is inserted, and remove the appropriate UIBarButtonItem
. 因此,我访问插入信息按钮的工具栏,并删除相应的
UIBarButtonItem
。
Create a subclass of ZBarReaderViewController: 创建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
Do not forget to instantiate this new subclass ( [ZBarReaderViewControllerWithoutInfoButton new]
instead of ``[ZBarReaderViewController new]`) when presenting the scanner view controller. 在呈现扫描仪视图控制器时,不要忘记实例化这个新的子类(
[ZBarReaderViewControllerWithoutInfoButton new]
而不是``[ZBarReaderViewController new]`)。
Before: 之前:
After: 后:
New solutions for new devices, as in iOS10 this Buttons its 2 instead of index3, here is the code with the before solution applied. 新设备的新解决方案,如iOS10中的那样按下它的2而不是index3,这里是应用了before解决方案的代码。
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];
Hope it helps, regards 希望它有所帮助,问候
不是你要求的,但要移除你可以使用的屏幕底部的整个栏
reader.showsZBarControls = NO;
Here is the working code block. 这是工作代码块。
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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.