How to hide info button in ZBar Bar Code Reader for iOS6.0 and above
Asked Answered
L

8

7

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.

Lecherous answered 3/5, 2013 at 7:8 Comment(0)
H
10

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.

Helmer answered 3/5, 2013 at 7:10 Comment(3)
Note that on iOS 10 (at least on the beta version) it has changed again. Now the button is at objectAtIndex:1 (vs. 3 for iOS 9 and below).Singsong
@Singsong Thank you for the update will test it and update it shorlty.Helmer
I Think it changed again ? I'm trying to migrate an old cordova plugin and it doesn't works.Psilocybin
A
6

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]

Anagrammatize answered 18/9, 2013 at 12:15 Comment(0)
C
3

Try this code :

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

[infoButton setHidden:YES];
Chum answered 3/5, 2013 at 7:13 Comment(1)
Isn't it the same answer given by icodebuster. you just copy-pasted it.Lecherous
D
3

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.

Create a subclass of 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.


Before:

Before, with info button

After:

After, without info button

Dormitory answered 22/8, 2014 at 13:0 Comment(1)
Great...Thanxxxx.Austriahungary
B
2

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];
Brooksbrookshire answered 6/8, 2013 at 2:16 Comment(0)
L
2

New solutions for new devices, as in iOS10 this Buttons its 2 instead of index3, here is the code with the before solution applied.

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

Lymphoma answered 27/9, 2016 at 13:24 Comment(0)
C
1

Not excatly what you asked for, but to remove the whole bar at the bottom of the screen you can use

reader.showsZBarControls = NO;
Challenging answered 8/4, 2014 at 10:35 Comment(0)
K
0

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];
Kor answered 27/10, 2016 at 17:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.