Fixed the size of the preview overlay

This commit is contained in:
Julian Finkler 2020-01-12 12:18:48 +01:00
parent 06f38e0b53
commit e0cc5c3bc2
2 changed files with 20 additions and 7 deletions

View File

@ -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];

View File

@ -83,13 +83,25 @@
}
- (CGRect)scanRect {
CGRect rect = self.frame;
CGFloat heightMultiplier = 3.0/4.0; // 4:3 aspect ratio
CGFloat scanRectWidth = rect.size.width * 0.8f;
CGFloat scanRectHeight = scanRectWidth * heightMultiplier;
CGFloat scanRectOriginX = (rect.size.width / 2) - (scanRectWidth / 2);
CGFloat scanRectOriginY = (rect.size.height / 2) - (scanRectHeight / 2);
return CGRectMake(scanRectOriginX, scanRectOriginY, scanRectWidth, scanRectHeight);
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 = widthOnPotrait * 0.8f;
CGFloat scanRectHeight = scanRectWidth * heightMultiplier;
if(isLandscape) {
CGFloat navbarHeight = 32;
frameHeight += navbarHeight;
}
CGFloat scanRectOriginX = (frameWidth - scanRectWidth) / 2;
CGFloat scanRectOriginY = (frameHeight - scanRectHeight) / 2;
return CGRectMake(scanRectOriginX, scanRectOriginY, scanRectWidth, scanRectHeight);
}
- (CGRect)scanLineRect {