iPhone iOS: Can you add crosshairs or other visual indicator to ZBar barcode scanning?
I wa开发者_JAVA百科nt to know if it is possible when using Zbar barcode scanning within an iPhone/iOS app to add some sort or crosshairs or other visual indicator to the screen to assist users in aiming their camera onto a QR code?
That is best accomplished with a transparent PNG. Just import it to your project and then create a new UIImageView
that you give to the reader.
I did this to add a logo:
// Create the reader
self.reader = [ZBarReaderViewController new];
self.reader.readerDelegate = self;
// Create image for adding a logo :)
UIImage *image = [UIImage imageNamed:@"scan_logo.png"];
UIImageView *imageLogo = [[UIImageView alloc] initWithImage:image];
imageLogo.frame = CGRectMake(0, 0, image.size.width, image.size.height);
// Configure reader
self.reader.cameraOverlayView = imageLogo;
To get the image in the center just change the frame positioning from:
imageLogo.frame = CGRectMake(0, 0, image.size.width, image.size.height);
To something like:
imageLogo.center = CGRectMake(320/2, 460/2, image.size.width, image.size.height);
FWIW what I did in my app is to extend the ZBarReaderViewController class, set my new class as the ZBarReaderDelegate also, and then put JeroenEijkhof's code into my init override:
- (id) init
{
self = [super init];
if( self ) {
self.readerDelegate = self;
UIImage *image = [UIImage imageNamed:...
...
}
return self;
}
This gave me the ability to control other aspects of the view, such as customizing the navigation controller on viewDidLoad
and viewWillAppear
since I was implementing the camera view in a NavigationController view stack and wanted the ability to add the titlebar, toolbar, etc. instead of presenting it modally, as the zbar docs demonstrate.
精彩评论