场景:
- scrollView.frame = viewController.bounds
- 要放大的view的宽度小于scrollView的宽度
问题:
当放大之后出现了偏移
加上如下代码 问题解决
func scrollViewDidZoom(scrollView: UIScrollView) {
let offsetX:CGFloat = (scrollView.bounds.size.width > scrollView.contentSize.width) ? (scrollView.bounds.size.width - scrollView.contentSize.width) * 0.5 : 0.0;
let offsetY:CGFloat = (scrollView.bounds.size.height > scrollView.contentSize.height) ? (scrollView.bounds.size.height - scrollView.contentSize.height) * 0.5 : 0.0;
self.drawView!.center = CGPointMake(scrollView.contentSize.width * 0.5 + offsetX,
scrollView.contentSize.height * 0.5 + offsetY);
}