ZBarReadview with custom size from StoryBoard,but

2019-07-24 09:38发布

问题:

i've got a ZBarReaderView created from storyboard with 300*90 px which is shown as roughly 200*400 px because ZBarReaderView doesn't take it's size too serious...

I Declare my IBOutlets as so:

@interface MYQViewController : UIViewController < ZBarReaderViewDelegate >
{
    ZBarReaderView *readerView;
    ZBarCameraSimulator *cameraSim;
    UITextView *resultText;
}
@property (strong, nonatomic) IBOutlet ZBarReaderView *readerView;
@property (strong, nonatomic) IBOutlet UITextView *resultText;
@end

in the 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;
    }
}

回答1:

I had a similar problem to solve. I created an UIView in Storyboard and assigned ZBarReaderView as class to it. When ZBarViewReaderView was started it extended my view by far.

I found the solution while comparing the example code (EmbeddedReader) to my code. It was pretty simple:

In Storyboard or Interface Builder, if your view is selected, you have to check the "Clip Subviews" checkmark. Now the camera image stays exactly where it should.

Here is a screenshot of the properties in Storyboard:

Hope I could help.