【发布时间】:2020-10-10 19:01:32
【问题描述】:
我正在尝试放大UIImageView 和UIView,它们位于UIScrollView 内,但它不起作用。
我有一个UIImage and CALayer,它们的大小相同(2048×2155)。这些组件封装在 UIImageView(图像视图)和 UIView(画布)中,并显示在 UIScrollView 中。
图像视图和画布具有相同的content scale factor,等于 2.0 (UIScreen.main.scale),但画布尺寸错误(见下图)。
CALayer 子层是使用CAShapeLayer and UIBezierPath 构建的。
UIScrollViewDelegate 看起来下一个:
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
canvas
}
func scrollViewDidZoom(_ scrollView: UIScrollView) {
self.scrollView.centerContentView()
}
接下来是中心内容视图(自定义 UIScrollView 中的方法):
func centerContentView() {
let boundsSize = bounds.size
var centerFrame = canvas.frame
if centerFrame.size.width < boundsSize.width {
centerFrame.origin.x = (boundsSize.width - centerFrame.size.width) / 2.0
} else {
centerFrame.origin.x = 0
}
if centerFrame.size.height < boundsSize.height {
centerFrame.origin.y = (boundsSize.height - centerFrame.size.height) / 2.0
} else {
centerFrame.origin.y = 0
}
imageView.frame = centerFrame
canvas.frame = centerFrame
}
我所有的努力都失败了。我试图用画布转换 CALayer 但无济于事。我将不胜感激任何建议或帮助。谢谢。
【问题讨论】: