I'm trying to check if a dictionary that is passed to a ViewController has a link to an image. If it has a link, I want to show the pic, using AlamofireImage.
If not, then simply remove the UIImageView from the scrollView, so the other items below the image would stick to the top of the screen.
Here's the setup:
UIScrollView
-> UIView
--> UIImageView
--> UILabel (some short text for title)
--> UILabel (some long text for content that makes the view scrollable)
I've setup my views through Interface Builder and Auto Layout like so:
UIImageView: top, left, right, bottom constraints with a 1:1 aspect ratio of height:width no particular height/width
UILabel: top (required priority) image, top (high priority) top-layout-guide, right, left, bottom constraints
2nd UILabel: top, left, right, bottom constraints
Inside ViewDidLoad
if let imageURLString = item["imageLink"] as? String {
let imageURL = NSURL(string: imageURLString)!
image.af_setImageWithURL(imageURL, placeholderImage: nil, filter: nil, imageTransition: .CrossDissolve(2), runImageTransitionIfCached: true, completion: nil)
}
else {
self.image.removeFromSuperview()
self.scrollView.setNeedsLayout()
}
With this code, when there is a link, it loads the image and everything is displayed well without messing the scrollView. But removing it from scrollView prevents the scrollView to be able to scroll. Even though the scroll bar indicator shows up and the view "tries" to scroll, but everything gets frozen!
