Ich habe diese UIViewController
Unterklasse:Scroll Ansicht ist nicht Inhalt vertikal mit Autolayout in Swift Scrollen
class MyCustomViewController: UIViewController, MyDelegate {
var scrollContainerView: UIView = {
let scrollContainerView = UIView(frame: CGRectZero)
scrollContainerView.translatesAutoresizingMaskIntoConstraints = false
return scrollContainerView
}()
var scrollView: UIScrollView = {
var scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
return scrollView
}()
lazy var customView: MyCustomView = {
var customView = MyCustomView(frame: .zero)
customView.translatesAutoresizingMaskIntoConstraints = false
customView.delegate = self
return customView
}()
override func loadView() {
self.view = UIView()
self.view.backgroundColor = UIColor.whiteColor()
self.view.addSubview(self.scrollView)
self.scrollView.addSubview(self.scrollContainerView)
self.scrollContainerView.addSubview(self.customView)
view.setNeedsUpdateConstraints()
}
override func updateViewConstraints() {
self.scrollView.autoPinEdge(.Top, toEdge: .Bottom, ofView: self.view, withOffset: 0)
self.scrollView.autoPinEdge(.Left, toEdge: .Left, ofView: self.view, withOffset: 0)
self.scrollView.autoPinEdge(.Right, toEdge: .Right, ofView: self.view, withOffset: 0)
self.scrollView.autoPinEdge(.Bottom, toEdge: .Bottom, ofView: self.view, withOffset: 0)
self.scrollContainerView.autoPinEdge(.Top, toEdge: .Bottom, ofView: self.scrollView, withOffset: 0)
self.scrollContainerView.autoPinEdge(.Left, toEdge: .Left, ofView: self.scrollView, withOffset: 0)
self.scrollContainerView.autoPinEdge(.Right, toEdge: .Right, ofView: self.scrollView, withOffset: 0)
self.scrollContainerView.autoPinEdge(.Bottom, toEdge: .Bottom, ofView: self.scrollView, withOffset: 0)
self.customView.autoPinEdge(.Top, toEdge: .Bottom, ofView: self.scrollContainerView, withOffset: 0)
self.customView.autoPinEdge(.Left, toEdge: .Left, ofView: self.scrollContainerView, withOffset: 0)
self.customView.autoPinEdge(.Right, toEdge: .Right, ofView: self.scrollContainerView, withOffset: 0)
self.customView.autoPinEdge(.Bottom, toEdge: .Bottom, ofView: self.scrollContainerView, withOffset: 0)
super.updateViewConstraints()
}
}
Wo customView
eine feste Größe hat. Wenn ich die App im iPhone 4S-Simulator starte, wo sie benötigt wird, um die komplette Ansicht zu scrollen, finde ich, dass sie horizontal scrollt, aber nicht vertikal ... Ich verstehe nicht, was ich vermissen könnte.
Sie müssen self.scrollContainerView constraint auch zu self.view hinzufügen. –
@ArunGupta, dass es nicht für mich funktioniert ... – AppsDev