我试图完成一个可以放大UIScrollView的场景。我已经看到,实现这一目标的最佳方法是拥有一个包罗万象的scrollView,它支持滚动,并且内部有另一个UIScrollViewView(而不是内部有UIImageView的普通应用程序)
以下是我所拥有的:
class Editor: UIViewController, UIScrollViewDelegate {
let menuHeight = CGFloat(60)
var editor: LevelScrollView? = nil
var scrollProxy = UIScrollView()
override func viewDidLoad() {
let contentFrame = CGRectMake(0,menuHeight,self.view.frame.width,self.view.frame.height-menuHeight)
scrollProxy.delegate = self
scrollProxy.backgroundColor = UIColor.redColor()
scrollProxy.frame = contentFrame
scrollProxy.showsHorizontalScrollIndicator = false
scrollProxy.showsVerticalScrollIndicator = false
scrollProxy.bounces = false
let editor = LevelScrollView(reference: scrollProxy)
self.editor = editor
scrollProxy.addSubview(editor)
scrollProxy.contentSize = self.editor!.contentSize
scrollProxy.minimumZoomScale = 1.0
scrollProxy.zoomScale = scrollProxy.minimumZoomScale
scrollProxy.maximumZoomScale = 20.0
}
func scrollViewWillBeginZooming(scrollView: UIScrollView, withView view: UIView?) {
print("scrollViewWillBeginZooming")
}
func scrollViewDidEndZooming(scrollView: UIScrollView, withView view: UIView?, atScale scale: CGFloat) {
print("scrollViewDidEndZooming")
}
func scrollViewDidZoom(scrollView: UIScrollView) {
print("scrollViewDidZoom")
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
return editor
}
}
一些注意事项:
因为缩放这些东西不起作用。我如何成功完成这项工作?
谢谢!
答案 0 :(得分:0)
我能找到的唯一解决方案是将整个scrollview嵌入到单独的UIView中,然后为其启用缩放。