i'm using BWWalkthrough Library for my personal Walkthrough. Its very simple to implement but i have a mistake with BWWalkthroughViewController: i wont use storyboard for create this Main controller so i've created my custom view via code and then in the viewDidLoad of BWWalkthroughViewController ive setted the view and the pageControl. The rest of code its the same of the example in the github repository.
that is the viewDidLoad of BWWalkthroughViewController:
override func viewDidLoad() {
super.viewDidLoad()
let welcomeview: WelcomeView = WelcomeView() // my custom view
view = welcomeview
self.pageControl = welcomeview.pageControl
...
}
and, because its the first view, the rootViewController is setted with BWWalkthroughViewController with viewDidLoad modified. So i have a func for setting this walkthrough in the AppDelegate.swift:
func showWelcomeView() -> BWWalkthroughViewController{
let storyboard = UIStoryboard(name: "Welcome", bundle: nil)
let walkthrough: BWWalkthroughViewController = BWWalkthroughViewController()
let page_zero = storyboard.instantiateViewControllerWithIdentifier("walk_0") as! UIViewController
let page_one = storyboard.instantiateViewControllerWithIdentifier("walk_1") as! UIViewController
let page_two = storyboard.instantiateViewControllerWithIdentifier("walk_2") as! UIViewController
let page_three = storyboard.instantiateViewControllerWithIdentifier("walk_3") as! UIViewController
let page_four = storyboard.instantiateViewControllerWithIdentifier("walk_4") as! UIViewController
walkthrough.delegate = self
walkthrough.addViewController(page_zero)
walkthrough.addViewController(page_one)
walkthrough.addViewController(page_two)
walkthrough.addViewController(page_three)
walkthrough.addViewController(page_four)
return walkthrough
}
Im using that func here:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = showWelcomeView() // func usedhere
return true
}
The app run without errors. I can see my custom view and all 4 subviews(walk_0 ... walk_4) and i can slide them but no correctly: the scrollable is free and doesn't stop on each page.
So... I've missed some step with my custom view? Help me please!
this is a screenshot from my IPhone with the scroll positioned between 2 subviews:
Ive fixed that by using the property of scrollview in BWWalkthroughViewController
override func viewDidLoad() {
super.viewDidLoad()
..
scrollview.pagingEnabled = true
}
Work fine, but dunno why. The default of that scrollview is pagingeEnabled = true
setted in the init:
required init(coder aDecoder: NSCoder) {
// Setup the scrollview
scrollview = UIScrollView()
scrollview.showsHorizontalScrollIndicator = false
scrollview.showsVerticalScrollIndicator = false
scrollview.pagingEnabled = true // Default of scrollview
// Controllers as empty array
controllers = Array()
super.init(coder: aDecoder)
}