Skip to content

Task/fix portrait images in landscape scaling #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions BFRImageViewController/BFRImageContainerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ - (void)viewWillLayoutSubviews {
//Scrollview
[self.scrollView setFrame:self.view.bounds];

//Set the aspect ration of the image
//Set the aspect ratio of the image
float hfactor = self.imgLoaded.size.width / self.view.bounds.size.width;
float vfactor = self.imgLoaded.size.height / self.view.bounds.size.height;
float factor = fmax(hfactor, vfactor);
float factor = fmax(hfactor, vfactor) < 1.0 ? 1.0 : fmax(hfactor, vfactor);

//Divide the size by the greater of the vertical or horizontal shrinkage factor
float newWidth = self.imgLoaded.size.width / factor;
Expand Down Expand Up @@ -134,14 +134,6 @@ - (UIImageView *)createImageView {
resizableImageView.contentMode = UIViewContentModeScaleAspectFill;
resizableImageView.backgroundColor = [UIColor colorWithWhite:0 alpha:1];

//Scale to keep its aspect ration
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenBound.size.width;
CGFloat screenHeight = screenBound.size.height;
float scaleFactor = (self.imgLoaded ? self.imgLoaded.size.width : screenWidth) / screenWidth;
CGRect finalImageViewFrame = CGRectMake(0, (screenHeight/2)-((self.imgLoaded.size.height / scaleFactor)/2), screenWidth, self.imgLoaded.size.height / scaleFactor);
resizableImageView.layer.frame = finalImageViewFrame;

//Toggle UI controls
UITapGestureRecognizer *singleImgTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissUI)];
singleImgTap.numberOfTapsRequired = 1;
Expand Down Expand Up @@ -264,6 +256,7 @@ - (void)handleDrag:(UIPanGestureRecognizer *)recognizer {

UIOffset centerOffset = UIOffsetMake(imgLocation.x - CGRectGetMidX(self.imgView.bounds),
imgLocation.y - CGRectGetMidY(self.imgView.bounds));

self.imgAttatchment = [[UIAttachmentBehavior alloc] initWithItem:self.imgView offsetFromCenter:centerOffset attachedToAnchor:location];
[self.animator addBehavior:self.imgAttatchment];
} else if (recognizer.state == UIGestureRecognizerStateChanged) {
Expand Down Expand Up @@ -310,6 +303,7 @@ - (void)retrieveImageFromAsset {
[self addImageToScrollView];
}];
}

- (void)retrieveImageFromURL {
NSURL *url = (NSURL *)self.imgSrc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
Expand Down