我有一个从故事板创建的 ZBarReaderView,大小为 300*90 像素,显示为大约 200*400 像素,因为 ZBarReaderView 并没有把它的尺寸看得太严重......
我这样声明我的 IBOutlets:
@interface MYQViewController : UIViewController < ZBarReaderViewDelegate >
{
ZBarReaderView *readerView;
ZBarCameraSimulator *cameraSim;
UITextView *resultText;
}
@property (strong, nonatomic) IBOutlet ZBarReaderView *readerView;
@property (strong, nonatomic) IBOutlet UITextView *resultText;
@end
在 viewDidLoad
-(void) viewDidLoad
{
readerView.readerDelegate = self;
readerView.zoom=1;
if(TAGET_IPONE_SIMULATOR)
{
cameraSim=[[ZBarCameraSimulator alloc] initWithViewController:self];
cameraSim.readerView=readerView;
}
}
-(void)Scan
{
if(readerView.hidden)
{
[readerView start];
readerView.hidden = NO;
resultText.text=EMPTY_STRING;
}
else
{
[readerView stop];
readerView.hidden = YES;
//OTHER CODES
}
}
-(void) readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet * )symbolsfromImage:(UIImage *)image
{
for (ZBarSymol *sym in symbols)
{
self.resultText.text=sym.data;
break;
}
}