Skip to content

Scrool Photos, verify if image is downloaded #41

Description

@narlei

Hello,

In my code, in function "- (void)layoutScrollViewAnimated:(BOOL)animated{" in file "EGOPhotoImageView.m" I add a verification if image exists: "if (self.imageView.image) {" :

  • (void)layoutScrollViewAnimated:(BOOL)animated{
    if (self.imageView.image) {

    if (animated) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.0001];
    }

    CGFloat hfactor = self.imageView.image.size.width / self.frame.size.width;
    CGFloat vfactor = self.imageView.image.size.height / self.frame.size.height;

    CGFloat factor = MAX(hfactor, vfactor);

    CGFloat newWidth = self.imageView.image.size.width / factor;
    CGFloat newHeight = self.imageView.image.size.height / factor;

    CGFloat leftOffset = (self.frame.size.width - newWidth) / 2;
    CGFloat topOffset = (self.frame.size.height - newHeight) / 2;

    self.scrollView.frame = CGRectMake(leftOffset, topOffset, newWidth, newHeight);
    self.scrollView.layer.position = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
    self.scrollView.contentSize = CGSizeMake(self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
    self.scrollView.contentOffset = CGPointMake(0.0f, 0.0f);
    self.imageView.frame = self.scrollView.bounds;

    if (animated) {
    [UIView commitAnimations];
    }
    }

}

With this, the code is working very fine.
Can you add this in project because I'm using CocoaPods.

Congratulations for your work!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions