Skip to content
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

it doesn't work when content contains dynamic image view #37

Closed
caofei10119 opened this issue Jun 1, 2015 · 9 comments
Closed

it doesn't work when content contains dynamic image view #37

caofei10119 opened this issue Jun 1, 2015 · 9 comments

Comments

@caofei10119
Copy link

I have one image view inside cell content that loads photo from server.
image view content mode is aspect fill and only width has been defined using autolayout in storyboard.
height should be increased dynamically based on loaded photo size.
constraints for cell content view has been already self-satisfied.
what am I missing?

@caofei10119
Copy link
Author

any thought?

@sunnyxx
Copy link
Member

sunnyxx commented Jun 3, 2015

If only width constraint has been set, auto layout engine cannot calculate out a right height for there are not enough informations to determine image view's intrinsic content size (aspect fill mode is not a constraint)

@caofei10119
Copy link
Author

so what is a solution? height constraint should be applied?

@sunnyxx
Copy link
Member

sunnyxx commented Jun 5, 2015

Yes, that's not avoidable.

@caofei10119
Copy link
Author

then all the images inside cell should have static height?

@sunnyxx
Copy link
Member

sunnyxx commented Jun 5, 2015

Image views in FDTemplateLayoutCell's demo don't have a width or height constraint because they are using local images, which image sizes are fixed, and will be translated to intrinsic content size constraints. However, your images are downloaded from server and don't know actual sizes before that, so you may try one of:

  • don't load your cells until all images done.
  • put a placeholder image and reload using real image.
  • add both width and height constraints, IBOutlet them, set their constant value by real image sizes.

This is a problem no matter whether you use FDTemplateLayoutCell's or not. The best solution is getting image's size at same time when you get image's url.

@caofei10119
Copy link
Author

suppose we know the width and height when get image url, where should width and height constraint constant be changed?

@sunnyxx
Copy link
Member

sunnyxx commented Jun 6, 2015

IBOutlet width and height constraints, reset their constant value when you configure cells, maybe look like:

// In your cell
- (void)setEntity:(YourEntity *)entity {
    self.imageViewWidthConstraint.constant = entity.imageSize.width;
    self.imageViewHeightConstraint.constant = entity.imageSize.height;
}

@caofei10119
Copy link
Author

thanks

@sunnyxx sunnyxx closed this as completed Sep 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants