mirror of
https://github.com/simplezhli/flutter_barcode_reader.git
synced 2024-12-23 16:19:19 +08:00
Fixed the size of the preview overlay
This commit is contained in:
parent
06f38e0b53
commit
e0cc5c3bc2
@ -16,6 +16,7 @@
|
||||
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];
|
||||
|
@ -84,11 +84,23 @@
|
||||
|
||||
- (CGRect)scanRect {
|
||||
CGRect rect = self.frame;
|
||||
|
||||
CGFloat frameWidth = rect.size.width;
|
||||
CGFloat frameHeight = rect.size.height;
|
||||
|
||||
BOOL isLandscape = frameWidth > frameHeight;
|
||||
CGFloat widthOnPotrait = isLandscape ? frameHeight : frameWidth;
|
||||
CGFloat heightMultiplier = 3.0/4.0; // 4:3 aspect ratio
|
||||
CGFloat scanRectWidth = rect.size.width * 0.8f;
|
||||
CGFloat scanRectWidth = widthOnPotrait * 0.8f;
|
||||
CGFloat scanRectHeight = scanRectWidth * heightMultiplier;
|
||||
CGFloat scanRectOriginX = (rect.size.width / 2) - (scanRectWidth / 2);
|
||||
CGFloat scanRectOriginY = (rect.size.height / 2) - (scanRectHeight / 2);
|
||||
|
||||
if(isLandscape) {
|
||||
CGFloat navbarHeight = 32;
|
||||
frameHeight += navbarHeight;
|
||||
}
|
||||
|
||||
CGFloat scanRectOriginX = (frameWidth - scanRectWidth) / 2;
|
||||
CGFloat scanRectOriginY = (frameHeight - scanRectHeight) / 2;
|
||||
return CGRectMake(scanRectOriginX, scanRectOriginY, scanRectWidth, scanRectHeight);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user