mirror of
https://github.com/simplezhli/flutter_barcode_reader.git
synced 2024-11-23 03:09:20 +08:00
Merge pull request #167 from mintware-de/fix_issue_61
Fix rotation in iOS
This commit is contained in:
commit
0ef78bb112
@ -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,35 @@
|
|||||||
@implementation BarcodeScannerViewController {
|
@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 stopAnimating];
|
||||||
|
[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 {
|
- (void)viewDidLoad {
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
@ -26,21 +55,7 @@
|
|||||||
options:NSLayoutFormatAlignAllBottom
|
options:NSLayoutFormatAlignAllBottom
|
||||||
metrics:nil
|
metrics:nil
|
||||||
views:@{@"previewView": _previewView}]];
|
views:@{@"previewView": _previewView}]];
|
||||||
self.scanRect = [[ScannerOverlay alloc] initWithFrame:self.view.bounds];
|
[self setupScanRect: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.scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:_previewView];
|
self.scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:_previewView];
|
||||||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];
|
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];
|
||||||
[self updateFlashButton];
|
[self updateFlashButton];
|
||||||
|
@ -84,18 +84,30 @@
|
|||||||
|
|
||||||
- (CGRect)scanRect {
|
- (CGRect)scanRect {
|
||||||
CGRect rect = self.frame;
|
CGRect rect = self.frame;
|
||||||
CGFloat heightMultiplier = 3.0/4.0; // 4:3 aspect ratio
|
|
||||||
CGFloat scanRectWidth = rect.size.width * 0.8f;
|
CGFloat frameWidth = rect.size.width;
|
||||||
CGFloat scanRectHeight = scanRectWidth * heightMultiplier;
|
CGFloat frameHeight = rect.size.height;
|
||||||
CGFloat scanRectOriginX = (rect.size.width / 2) - (scanRectWidth / 2);
|
|
||||||
CGFloat scanRectOriginY = (rect.size.height / 2) - (scanRectHeight / 2);
|
BOOL isLandscape = frameWidth > frameHeight;
|
||||||
|
CGFloat widthOnPortrait = isLandscape ? frameHeight : frameWidth;
|
||||||
|
CGFloat scanRectWidth = widthOnPortrait * 0.8f;
|
||||||
|
CGFloat aspectRatio = 3.0/4.0;
|
||||||
|
CGFloat scanRectHeight = scanRectWidth * aspectRatio;
|
||||||
|
|
||||||
|
if(isLandscape) {
|
||||||
|
CGFloat navbarHeight = 32;
|
||||||
|
frameHeight += navbarHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
CGFloat scanRectOriginX = (frameWidth - scanRectWidth) / 2;
|
||||||
|
CGFloat scanRectOriginY = (frameHeight - scanRectHeight) / 2;
|
||||||
return CGRectMake(scanRectOriginX, scanRectOriginY, scanRectWidth, scanRectHeight);
|
return CGRectMake(scanRectOriginX, scanRectOriginY, scanRectWidth, scanRectHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGRect)scanLineRect {
|
- (CGRect)scanLineRect {
|
||||||
CGRect scanRect = [self scanRect];
|
CGRect scanRect = [self scanRect];
|
||||||
CGRect rect = self.frame;
|
CGFloat positionY = scanRect.origin.y + (scanRect.size.height / 2);
|
||||||
return CGRectMake(scanRect.origin.x, rect.size.height / 2, scanRect.size.width, 1);
|
return CGRectMake(scanRect.origin.x, positionY, scanRect.size.width, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
Reference in New Issue
Block a user