I'm trying to use a swipe based feature in my app where I can swipe between different view controllers. I followed this tutorial https://www.youtube.com/watch?v=3jAlg5BnYUU&lc=z12ztbcpgsq5cve2h225vpqr0valjttwg04 and it worked fine when I used xib files as the interface for the view controllers. The only problem was that I couldn't use buttons in the xib files to go to another View Controller.
So I used storyboard Identifiers instead and this solved the problem of using a button to go to the next VC, but the view controllers just aren't sizing up to their width as they are supposed to. It's seems like some invisible constraints have just made the views shrink.
Here's my code:
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 3, self.view.frame.height - 66)
let vc0 = self.storyboard?.instantiateViewControllerWithIdentifier("FirstPage")
self.addChildViewController(vc0!)
self.scrollView.addSubview(vc0!.view)
vc0!.didMoveToParentViewController(self)
let vc1 = self.storyboard?.instantiateViewControllerWithIdentifier("SecondPage")
let vc1Controller = ViewController1()
var frame1 = vc1Controller.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)
let vc2 = self.storyboard?.instantiateViewControllerWithIdentifier("ThirdPage")
let vc2Controller = ViewController2()
var frame2 = vc2Controller.view.frame
frame2.origin.x = self.view.frame.size.width * 2
vc2!.view.frame = frame2
self.addChildViewController(vc2!)
self.scrollView.addSubview(vc2!.view)
vc2!.didMoveToParentViewController(self)
}
Thanks in advance.