简体   繁体   中英

ZBar : custom button in Camera overlay view is not working

I'm using the ZBar SDK to read QR codes on iPhone, however I added a button in that view. But the button is not working! Even i tap the button it doesn't go to the action method of that button. Where is the problem actually? Thanks in advance for the help.

-(UIView *)setSettingsButton
{

    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [view setBackgroundColor:[UIColor clearColor]];
    UIToolbar *myToolBar = [[UIToolbar alloc] init];

    UIBarButtonItem *button=[[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStyleBordered target:self action:@selector(settingsAction)];

    [myToolBar setItems:[NSArray arrayWithObjects:button,nil]];    

    settingsLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 37, 281, 77)];
    [settingsLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:16]];
    [settingsLabel setTextAlignment:UITextAlignmentCenter];
    [settingsLabel setBackgroundColor:[UIColor clearColor]];
    [settingsLabel setTextColor:[UIColor blueColor]];
    [settingsLabel setNumberOfLines:1];
    [settingsLabel setText:@"For settings scan admin QR"];
    [view addSubview:settingsLabel];

    settingsLabel.hidden = YES;

    [myToolBar setBarStyle:UIBarStyleDefault];
    CGRect toolBarFrame;
    toolBarFrame = CGRectMake(0, 436, 320, 44);
    [myToolBar setFrame:toolBarFrame];
    [view addSubview:myToolBar];
    return  view;
}
-(void)settingsAction
{

    settingsLabel.hidden = NO;

}

I can't see where the problem is, but if it helps, I've customized zBar camera views without any problems.

The most likely answer is that a clear views is obscuring the tool-bar view. Here's a library for debugging UIViews: https://github.com/domesticcatsoftware/DCIntrospect

I had the same problem once. It was because my view was too big. Try to change the view's size like UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 380)]; , you'll see if it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM