Add overlay over top of ZBar scanner

久未见 提交于 2019-12-07 08:19:05

问题


I'm using the ZBar SDK to read QR codes on iPhone, however I want to add some text to the bottom of the camera/scanner view that is instructional text for the user. Here is what I have so far:

UIView *cameraOverlayView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    cameraOverlayView.backgroundColor = [UIColor redColor];

    UILabel *instructionLabel = [[UILabel alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    [instructionLabel setTextColor:[UIColor grayColor]];
    [instructionLabel setBackgroundColor:[UIColor clearColor]];
    [instructionLabel setFont:[UIFont fontWithName: @"Trebuchet MS" size: 24.0f]];
    [instructionLabel setCenter:cameraOverlayView.center];
    [cameraOverlayView addSubview:instructionLabel];

    reader.cameraOverlayView = cameraOverlayView;
    reader.wantsFullScreenLayout = YES;

    [instructionLabel release];
    [cameraOverlayView release];

Here is the full class:

https://gist.github.com/4163761

Unfortunately, the label doesn't show. ZBar's documentation says to use the cameraOverlayView for this purpose, however it doesn't seem to be working.

One other note, I'm using the Titanium framework, so that's where the extra Titanium classes are from, however my question should be specific to ZBar.


回答1:


Do you see the cameraOverlayView at all? set the background color to red or something: cameraOverlayView.backgroundColor = [UIColor redColor];

If you don't see the cameraOverlayView at all, then probably you need to set reader. showsZBarControls = NO which will disable the the default controls and use your custom overlay.

If you do see the cameraOverlayView, then the label is probably outside the bounds. Play around with the origin points and get it into position.

BTW I see you're not using ARC, make sure you release instructionLabel!



来源:https://stackoverflow.com/questions/13613476/add-overlay-over-top-of-zbar-scanner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!