gpt4 book ai didi

ios - ScrollView 不缩放和水平滚动一起吗?

转载 作者:行者123 更新时间:2023-11-30 10:52:11 25 4
gpt4 key购买 nike

我是 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
}

最佳答案

三个步骤:

  1. 首先:确保 ScrollView 的最大缩放比例更大高于默认值 1.0。如果出现以下情况,您可以在 Interface Builder 中更改此设置:您想要的,或者在代码中使用 maximumZoomScale 属性。
  2. 使您的 View Controller 成为 ScrollView 的委托(delegate)
  3. 使您的 View Controller 符合 UIScrollViewDelegate 协议(protocol),然后添加 viewForZooming(in:)

    func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? { 
    return imageView
    }

关于ios - ScrollView 不缩放和水平滚动一起吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54343223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com