作者:谭小牙笑不漏齿 | 来源:互联网 | 2023-05-21 19:26
1> 小智..:
小猪支持pic-o-matic的回答.我有一个案例,我需要将图像居中,只要它小于滚动视图框架.使用插图为简单的解决方案.
if imageView.frame.height <= scrollView.frame.height {
let shiftHeight = scrollView.frame.height/2.0 - scrollView.contentSize.height/2.0
scrollView.contentInset.top = shiftHeight
}
if imageView.frame.width <= scrollView.frame.width {
let shiftWidth = scrollView.frame.width/2.0 - scrollView.contentSize.width/2.0
scrollView.contentInset.left = shiftWidth
}