Ich habe zwei UIViewControllers
mit Storyboard Identifier "vc0" und "vc1", die ich Objekte innerhalb einer UIScrollView
mit aktiviertem Paging zu instanziieren, so dass die beiden View-Controller nebeneinander sind . Das Ziel besteht darin, den Benutzer nach links und rechts wischen zu lassen, um zwischen Ansichtencontrollern zu wischen, ähnlich wie SnapChat.ViewController Constraints in UIScrollView, mit Storyboard
Wenn ich meinen Code ausführe, enthält die erste Seite des Scrollview den ersten View-Controller, während die zweite Seite gar nichts enthält. Ich gehe davon aus, dass dies daran liegt, dass der erste View-Controller den zweiten überlappt. Wie kann ich meine Einschränkungen (oder irgendetwas anderes) ändern, um dieses Problem zu beheben, so dass die rechte Kante von vc0 mit der linken Kante von vc1 zusammentrifft?
Das UIScrollView ist in einer UIView innerhalb eines View-Controllers enthalten. Hier ist die ViewDidLoad(), die den gesamten relevanten Code enthält. Bitte informieren Sie mich über weitere hilfreiche Informationen, die ich zur Verfügung stellen sollte.
override func viewDidLoad()
{
super.viewDidLoad()
let screenWidth = self.view.frame.width
let screenHeight = self.view.frame.height
let vc0 = self.storyboard?.instantiateViewControllerWithIdentifier("vc0")
self.addChildViewController(vc0!)
self.scrollView.addSubview(vc0!.view)
vc0!.didMoveToParentViewController(self)
let vc1 = self.storyboard?.instantiateViewControllerWithIdentifier("vc1")
var frame1 = vc1!.view.frame
frame1.origin.x = self.view.frame.size.width
vc1!.view.frame = frame1
self.addChildViewController(vc1!)
self.scrollView.addSubview(vc1!.view)
vc1!.didMoveToParentViewController(self)
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height);
//ADD CONSTRAINTS TO vc0
vc0!.view.translatesAutoresizingMaskIntoConstraints = false
let horizontalConstraint = NSLayoutConstraint(item: vc0!.view, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: scrollView, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0)
view.addConstraint(horizontalConstraint)
let widthConstraint = NSLayoutConstraint(item: vc0!.view, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: screenWidth)
view.addConstraint(widthConstraint)
let heightConstraint = NSLayoutConstraint(item: vc0!.view, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: screenHeight)
view.addConstraint(heightConstraint)
//ADD CONSTRAINTS TO vc1
vc1!.view.translatesAutoresizingMaskIntoConstraints = false
let horizontalConstraint2 = NSLayoutConstraint(item: vc1!.view, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: vc0!.view, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0)
view.addConstraint(horizontalConstraint2)
let widthConstraint2 = NSLayoutConstraint(item: vc1!.view, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: screenWidth)
view.addConstraint(widthConstraint)
let heightConstraint2 = NSLayoutConstraint(item: vc1!.view, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: screenHeight)
view.addConstraint(heightConstraint)
}
Keine Notwendigkeit helfen, das Rad neu zu erfinden Es gibt viele Open-Source-Bibliotheken da draußen, dh https://github.com/goktugyil/EZSwipeController – t0day
@ t0day Man muss das Rad neu erfinden, wenn es besser wäre als die bestehenden. :) – BangOperator