图片显示不正常,我想像Facebook图片一样展示

时间:2017-07-10 06:48:27

标签: ios objective-c facebook imageview

我必须尝试所有类型的内容模式,第三方和大量的谷歌搜索。 但是,对我来说并不成功。 我想像Facebook图片帖子一样展示。 我们在Facebook上发布图片,脸谱显示正确的图像,并将图像非常正确地填充到图像视图中。

2 个答案:

答案 0 :(得分:0)

按照步骤

  1. setImage to UIImageView(with from z3 import * ackermann=Function('ackermann',IntSort(),IntSort(),IntSort()) m=Int('m') n=Int('n') s=Solver() s.add(ForAll([n,m],Implies(And(n>=0,m>=0),ackermann(m,n) == If(m!=0,If(n!=0,ackermann(m - 1,ackermann(m,n - 1)),If(n==0,ackermann(m - 1,1),If(m==0,n + 1,0))),If(m==0,n + 1,0))))) s.add(n>=0) s.add(m>=0) s.add(Not(Implies(ackermann(m,n)>=0,ackermann(m+1,0)>=0))) s.check()
  2. 获取imageSize UIViewContentModeScaleAspectFit
  3. UIImageView调整大小。 (CGSize imageSize = imageView.image.size)
  4. 移动你想要的位置。

    [imageView sizeThatFits:imageSize]

答案 1 :(得分:0)

设置UIImageView size == image(ratio):

@IBOutlet weak var heightConstraint: NSLayoutConstraint!
@IBOutlet weak var widthConstraint: NSLayoutConstraint!

func setImage(image: UIImage) {
    imageView.image = image
    let screenSize = UIScreen.main.bounds.size

    let imageAspectRatio = image.size.width / image.size.height
    let screenAspectRatio = screenSize.width / screenSize.height

    if imageAspectRatio > screenAspectRatio {
        widthConstraint.constant = min(image.size.width, screenSize.width)
        heightConstraint.constant = widthConstraint.constant / imageAspectRatio
    }
    else {
        heightConstraint.constant = min(image.size.height, screenSize.height)
        widthConstraint.constant = heightConstraint.constant * imageAspectRatio
    }
    view.layoutIfNeeded()
}

参考链接AutoLayout: UIImageView and Aspect Fit content mode