gpt4 book ai didi

ios - 我想在几个不同的 ViewController 上设置几个不同的 Scrollview

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

我在将 ScrollView 添加到几个不同的 View Controller 时遇到问题 - 到目前为止,我已经在 View Controller 的前端侧,但是,我无法弄清楚如何使它们工作(我是初学者)

这是代码

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

最佳答案

首先通过 firstscrollView.delegate = selfsecondscrollView.delegate = selfUIScrollView 分配 delegate viewDidLoad

然后在委托(delegate)方法中检查 UIScrollView 像这样

func viewForZooming(in scrollView: UIScrollView) -> UIView? {

if scrollView == firstscrollView {
return firstimageview
} else if scrollView == secondscrollView {
return secondscrollView
}
return nil
}

我希望这会有所帮助。

关于ios - 我想在几个不同的 ViewController 上设置几个不同的 Scrollview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41150343/

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