我无法将scrollview添加到几个不同的View控制器 - 到目前为止,我已经在视图控制器的前端,但是,我还没有弄清楚如何让它们工作(我是初学者)
这是代码
class ViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var firstscrollView: UIScrollView!
@IBOutlet weak var firstimageview: UIImageView!
@IBOutlet weak var secondscrollView: UIScrollView!
@IBOutlet weak var secondimageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.firstscrollView.minimumZoomScale = 1.0
self.firstscrollView.maximumZoomScale = 6.0
self.secondscrollView.minimumZoomScale = 1.0
self.secondscrollView.maximumZoomScale = 6.0
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func viewForZooming(in firstscrollView: UIScrollView) -> UIView? {
return self.firstimageview
return self.secondimageView
}
}
答案 0 :(得分:0)
首先delegate
为UIScrollView
和firstscrollView.delegate = self
secondscrollView.delegate = self
分配viewDidLoad
。
然后在委托方法中检查UIScrollView
这样的
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
if scrollView == firstscrollView {
return firstimageview
} else if scrollView == secondscrollView {
return secondscrollView
}
return nil
}
我希望这会有所帮助。