Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

I have made info button hidden using following code on 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.

like image 362
Prasen Avatar asked May 03 '13 07:05

Prasen


4 Answers

Try this code, this worked for me on iOS5.0 and above.

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.

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.

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.

like image 70
icodebuster Avatar answered Sep 21 '22 21:09

icodebuster


With the last version of ZBar I solded this problem with another path:

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]

like image 31
Ragen Dazs Avatar answered Sep 20 '22 21:09

Ragen Dazs


Try this code :

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

[infoButton setHidden:YES];
like image 43
Priyank Gandhi Avatar answered Sep 22 '22 21:09

Priyank Gandhi


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];
like image 44
DevonDahon Avatar answered Sep 22 '22 21:09

DevonDahon