gpt4 book ai didi

ios - ContainerView Inside ScrollView 不要在 Swift 3 中滚动

转载 作者:可可西里 更新时间:2023-11-01 00:35:42 26 4
gpt4 key购买 nike

我在 GitHub 上有示例项目,您可以在 -> 上看到 https://github.com/LetSwiftDev/ContainerViewInsideScroll/tree/master

我有两个, View Controller ,一个是普通的 View Controller ,名为 oneViewController 第二个是 twoViewController 里面有 UIScrollView 当我点击 OPEN TWO 按钮将转到 ContainerView 内的 twoViewController 但是;

My twoViewController have different height size like 1500 and inside have scrollview and don't scroll to bottom? I didn't see middle side, bottom side labels.

我该如何解决?有什么想法吗?

下面还有我的 centerViewController 代码。我正在使用 centerViewController

控制过去的 View Controller
import UIKit

open class centerViewController: UIViewController {
fileprivate weak var viewController : UIViewController!
fileprivate var containerViewObjects = Dictionary<String,UIViewController>()

open var currentViewController : UIViewController{
get {
return self.viewController

}
}


fileprivate var segueIdentifier : String!

@IBInspectable internal var startUp : String!


override open func viewDidLoad() {
super.viewDidLoad()



}
open override func viewDidAppear(_ animated: Bool) {
if let identifier = startUp{
segueIdentifierReceivedFromParent(identifier)
}
}
override open func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

func segueIdentifierReceivedFromParent(_ identifier: String){

self.segueIdentifier = identifier
self.performSegue(withIdentifier: self.segueIdentifier, sender: nil)

}




override open func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == segueIdentifier{

if viewController != nil{


viewController.view.removeFromSuperview()
viewController = nil

}
if ((self.containerViewObjects[self.segueIdentifier] == nil)){
viewController = segue.destination
self.containerViewObjects[self.segueIdentifier] = viewController

}else{
for (key, value) in self.containerViewObjects{

if key == self.segueIdentifier{

viewController = value


}

}


}

self.addChildViewController(viewController)
viewController.view.frame = CGRect(x: 0,y: 0, width: self.view.frame.width,height: self.view.frame.height)
self.view.addSubview(viewController.view)
viewController.didMove(toParentViewController: self)


}

}


}

最佳答案

这是带有解决方案的演示。你可以在这里下载 https://www.dropbox.com/s/zvrjd0gp06xe5nw/ContainerViewInsideScroll-master%202.zip?dl=0

问题是你必须学习 Scrollview 的自动布局。

我只是针对给定的 ScrollView 约束提供提示。

先取scrollview适配屏幕,如下约束

Image

现在在 scrollview 中获取一个 View 并适合 scrollview 并给出类似的约束

image2

仍然给出约束错误。所以现在,给 scrollview 相同的 View 宽度

image3

现在您可以根据需要进行任意多的控制,并像我们对其他控件一样正常地给予约束。

希望你能理解。
享受编码。

关于ios - ContainerView Inside ScrollView 不要在 Swift 3 中滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43910755/

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