1

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:enter image description here

joern
  • 27,354
  • 7
  • 90
  • 105
Patonz
  • 884
  • 1
  • 6
  • 17

3 Answers3

1

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)
}
Patonz
  • 884
  • 1
  • 6
  • 17
  • bro could you help me to take a look at my question https://stackoverflow.com/questions/45004255/how-to-add-label-in-bwwalkthrough-view-controller-with-swift-3 ? – May Phyu Jul 10 '17 at 07:06
1

add following function in BWWalkthroughViewController class.

override func viewDidLayoutSubviews(){
    // Constraints
        let metricDict = ["w":view.bounds.size.width,"h":view.bounds.size.height]

        // - Generic cnst
        for vc in controllers {
            vc.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[view(h)]", options:[], metrics: metricDict, views: ["view":vc.view]))
            vc.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[view(w)]", options:[], metrics: metricDict, views: ["view":vc.view]))
            scrollview.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[view]|", options:[], metrics: nil, views: ["view":vc.view,]))
        }
    }

Remove following lines from addViewController function

// Constraints
let metricDict = ["w":vc.view.bounds.size.width,"h":vc.view.bounds.size.height]
    // - Generic cnst
        vc.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[view(h)]", options:[], metrics: metricDict, views: ["view":vc.view]))
        vc.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[view(w)]", options:[], metrics: metricDict, views: ["view":vc.view]))
        scrollview.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[view]|", options:[], metrics: nil, views: ["view":vc.view,]))
Muhammad Qasim
  • 159
  • 2
  • 7
0

Did you connect

@IBOutlet var pageControl:UIPageControl?

in BWWalkthroughViewController with the page controller in your view controller?

enter image description here

rednivlat
  • 135
  • 2
  • 2
  • 11
  • i cant connect this direclty, because i have my custom class... or tell me how i can connect that^^ – Patonz May 19 '15 at 13:37
  • Navigate to BWWalkthroughViewController and locate the line I have highlighted in the image above. Click and drag the empty dot in the left gutter, to the page control view in the view controller. – rednivlat May 19 '15 at 14:42
  • @rednivlat, bro could you help me to take a look at my question https://stackoverflow.com/questions/45004255/how-to-add-label-in-bwwalkthrough-view-controller-with-swift-3 ? – May Phyu Jul 10 '17 at 07:05