【发布时间】:2019-11-16 15:29:54
【问题描述】:
我目前有一个ScrollView,在ScrollView 里面我有一个UIImageView。
我从我的服务器获得不同尺寸的图像,并且大多数图像都大于我屏幕的bounds。
如果图片比我的屏幕大,我想滚动浏览它。
这样的……
这是我迄今为止尝试过的。
let image = UIImage(named: "myImg")
let heightInPoints = image?.size.height
let heightInPixels = heightInPoints ?? 0 * image!.scale
let widthInPoints = image?.size.width
let widthInPixels = widthInPoints ?? 0 * image!.scale
self.imageView.frame = CGRect(x: 0, y: 0, width: widthInPixels, height: heightInPixels) //= image
self.imageView.image = image
scrollView.contentSize = CGSize(width: imageView.frame.width, height: imageView.frame.height)
但它似乎不起作用。它要么只垂直或水平滚动,要么从不滚动。
我做错了什么。或者有没有更好的方法来获得这种效果?
【问题讨论】:
-
尝试查看这篇文章Look here 它包含有关您的实施的有用信息
-
@MertalpTasdelen 这不是我想要的。我不想缩放图像....我想计算它的帧大小并使图像视图的大小相同,然后将其添加到滚动视图中,以便我可以向各个方向滚动。
标签: ios swift uiscrollview uiimageview uiimage