IFTTT / RazzleDazzle

A simple keyframe-based animation framework for iOS, written in Swift. Perfect for scrolling app intros.
http://ifttt.github.io
MIT License
3.36k stars 291 forks source link

How can I implement the page indicator from the IFTTT app? #35

Open SikandAlex opened 8 years ago

SikandAlex commented 8 years ago

Is there an option to enable that page indicator at the bottom of the intro to IFTTT app? screenshot_20160825-133355

getaaron commented 8 years ago

There's no built-in page control, but you can trivially create one:

let pageControl: UIPageControl = {
    let control = UIPageControl()
    control.translatesAutoresizingMaskIntoConstraints = false
    control.currentPage = 0
    control.pageIndicatorTintColor = UIColor.yellowColor()
    control.currentPageIndicatorTintColor = UIColor.purpleColor()
    return control
}()

Configure it in viewDidLoad:

pageControl.numberOfPages = 4 // make sure this is correct

view.addSubview(pageControl)

// constrain the page control's location
NSLayoutConstraint(item: pageControl, attribute: .Bottom, relatedBy: .Equal, toItem: contentView, attribute: .Bottom, multiplier: 1, constant: -20).active = true
NSLayoutConstraint(item: pageControl, attribute: .CenterX, relatedBy: .Equal, toItem: view, attribute: .CenterX, multiplier: 1, constant: 0).active = true

Finally, in the scroll view delegate, update the current page:

override func scrollViewDidScroll(scrollView: UIScrollView) {
    animator.animate(scrollView.contentOffset.x)

    // …

    let currentPage = Int(scrollView.contentOffset.x / pageWidth)
    pageControl.currentPage = currentPage
}
nharbo commented 7 years ago

This if fucking up the animations :) .. It shows the pagecontrol, but its not working properly

ghost commented 7 years ago

@nharbo instead of complaining, you can look into the implementation and if you didn't do that, here is how you can fix it : Just call super.scrollViewDidScroll(scrollView) and animation should work fine again