mirror of
https://github.com/simplezhli/flutter_barcode_reader.git
synced 2024-11-22 21:49:20 +08:00
Fix for Issue #61
While the iOS device is rotating the bounds of the previewView will be recalculated and the scanRect will be reinitialized Changes in the WorkspaceSettings are necessary to run the example app
This commit is contained in:
parent
39ecc57bc0
commit
06f38e0b53
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildSystemType</key>
|
||||
<string>Original</string>
|
||||
<key>PreviewsEnabled</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
@ -10,6 +10,34 @@
|
||||
@implementation BarcodeScannerViewController {
|
||||
}
|
||||
|
||||
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
|
||||
{
|
||||
CGRect bounds = [UIScreen mainScreen].bounds;
|
||||
CGRect reversedBounds = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.height, bounds.size.width);
|
||||
self.previewView.bounds = reversedBounds;
|
||||
self.previewView.frame = reversedBounds;
|
||||
[self.scanRect removeFromSuperview];
|
||||
[self setupScanRect:reversedBounds];
|
||||
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
||||
}
|
||||
|
||||
- (void)setupScanRect:(CGRect)bounds {
|
||||
self.scanRect = [[ScannerOverlay alloc] initWithFrame:bounds];
|
||||
self.scanRect.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
self.scanRect.backgroundColor = UIColor.clearColor;
|
||||
[self.view addSubview:_scanRect];
|
||||
[self.view addConstraints:[NSLayoutConstraint
|
||||
constraintsWithVisualFormat:@"V:[scanRect]"
|
||||
options:NSLayoutFormatAlignAllBottom
|
||||
metrics:nil
|
||||
views:@{@"scanRect": _scanRect}]];
|
||||
[self.view addConstraints:[NSLayoutConstraint
|
||||
constraintsWithVisualFormat:@"H:[scanRect]"
|
||||
options:NSLayoutFormatAlignAllBottom
|
||||
metrics:nil
|
||||
views:@{@"scanRect": _scanRect}]];
|
||||
[_scanRect startAnimating];
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
@ -26,21 +54,7 @@
|
||||
options:NSLayoutFormatAlignAllBottom
|
||||
metrics:nil
|
||||
views:@{@"previewView": _previewView}]];
|
||||
self.scanRect = [[ScannerOverlay alloc] initWithFrame:self.view.bounds];
|
||||
self.scanRect.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
self.scanRect.backgroundColor = UIColor.clearColor;
|
||||
[self.view addSubview:_scanRect];
|
||||
[self.view addConstraints:[NSLayoutConstraint
|
||||
constraintsWithVisualFormat:@"V:[scanRect]"
|
||||
options:NSLayoutFormatAlignAllBottom
|
||||
metrics:nil
|
||||
views:@{@"scanRect": _scanRect}]];
|
||||
[self.view addConstraints:[NSLayoutConstraint
|
||||
constraintsWithVisualFormat:@"H:[scanRect]"
|
||||
options:NSLayoutFormatAlignAllBottom
|
||||
metrics:nil
|
||||
views:@{@"scanRect": _scanRect}]];
|
||||
[_scanRect startAnimating];
|
||||
[self setupScanRect:self.view.bounds];
|
||||
self.scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:_previewView];
|
||||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];
|
||||
[self updateFlashButton];
|
||||
|
Loading…
Reference in New Issue
Block a user