我是iOS编程的新手。我想进行缩放和水平滚动。页面加载完成后,我无法向上滚动以进行缩放。当我捏时,我就可以滚动。这是什么原因?
这是我的代码。
override func viewDidLoad() {
super.viewDidLoad()
scrollview.delegate = self
//mark:- for scrolling
let scrollViewFrame = scrollview.frame
let scaleWidth = scrollViewFrame.size.width / scrollview.contentSize.width
let scaleHeight = scrollViewFrame.size.height / scrollview.contentSize.height
let minScale = min(scaleWidth, scaleHeight);
scrollview.minimumZoomScale = minScale;
scrollview.maximumZoomScale = 1.0
scrollview.zoomScale = 0.8
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
statsView.drawStatsView(color: #colorLiteral(red: 0.9529411793, green: 0.6862745285, blue: 0.1333333403, alpha: 1), average: 100, min: 90, max: 110, name: "H")
statsView.drawStatsView(color: #colorLiteral(red: 0.7450980544, green: 0.1568627506, blue: 0.07450980693, alpha: 1), average: 120, min: 102, max: 122, name: "A")
statsView.drawStatsView(color: #colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1), average: 145, min: 130, max: 150, name: "Y")
}
override func viewDidLayoutSubviews() {
// bunu bi düşün containera statsView.Container.addConstraint()
scrollview.contentSize = CGSize(width: 720, height: scrollview.frame.height)
scrollview.alwaysBounceHorizontal = false
scrollview.bounces = false
scrollview.clipsToBounds = true
}
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
print("we re zooming yey")
return statsView
}
答案 0 :(得分:0)
三个步骤:
maximumZoomScale
属性。 delegate
。使您的视图控制器符合UIScrollViewDelegate
协议,然后添加viewForZooming(in:)
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
return imageView
}