您可以使用SDWebImage或翠鸟显示占位符图像和高速缓存... 然后在其完成块写代码来调整的ImageView
@IBOutlet weak var yourImageView: UIImageView!
func loadImage(){
SDWebImageManager.sharedManager().downloadImageWithURL(imgURL, options: SDWebImageOptions.CacheMemoryOnly, progress: { (received, expected) -> Void in
}) { (theImage : UIImage!, error : NSError!, cacheType : SDImageCacheType!, bool : Bool, imageUrl : NSURL!) -> Void in
let aspect = theImage.size.width/theImage.size.height
self.aspectConstraint = NSLayoutConstraint(item: self.yourImageView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self.yourImageView, attribute: NSLayoutAttribute.Height, multiplier: aspect, constant: 1.2)
self.yourImageView.image = theImage
}
}//loadImage
var aspectConstraint: NSLayoutConstraint? {
willSet {
if((aspectConstraint) != nil) {
self.yourImageView.removeConstraint(self.aspectConstraint!)
}
}
didSet {
if(aspectConstraint != nil) {
self.yourImageView.addConstraint(self.aspectConstraint!)
}
}
}
希望这有助于。
似乎对我来说是一个足够好的解决方案。我所做的是将图像缩放到图像的高度,然后在.center,.left和.right之间切换。尽管如此,将会把你的答案作为答案。 –
很高兴能帮到你! –