Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Tinder/Twitter like slider paging navigation and menu

I'm looking for examples/tutorials/framework explaining how to do a navigation bar/controller which slide to left and right like Tinder.app and Twitter.app I'm not talking about the faces swiping thing of Tinder, I'm talking about the top menu and the views we can slide entirely to left or right to go smoothly to other screens of the app like profile, moments, etc

I'm looking around but not find anything really interesting until then, I hope you can point me out something.

like image 621
Sylver Avatar asked Sep 06 '14 08:09

Sylver


3 Answers

I'm afraid that the complete solution to this is quite a bit beyond the scope of a single question.

However in the interest of trying to help you I think it's worth looking into this - That's a link to Cocoa Controls, a website which people build ready to go controls you can just drop into your app. (it's quite a cool site really).

That particular link is to MSSlidingPanelController. Which I think is exactly what you are looking for. The source code is clearly visible so you can see exactly what's required to get the effect you are looking for.

Here are a few other examples. Hope this helps.

like image 189
Woodstock Avatar answered Nov 10 '22 09:11

Woodstock


MSSlidingPanelController is not what you are looking for. These are "drawer views", which only allows user to swipe to a certain drawer.

TwitterPagingViewer and SwiftPagingNav is exactly like the one on Twitter, only more complicated.

Tinder seems to be using a UIPageViewController with hidden dots, which is done by deleting these methods:

presentationCountForPageViewController
presentationIndexForPageViewController

Here is a good tutorial:

https://www.youtube.com/watch?v=8bltsDG2ENQ

Here is a great repo:

https://github.com/goktugyil/EZSwipeController

like image 29
Esqarrouth Avatar answered Nov 10 '22 07:11

Esqarrouth


If you need it in Swift, I've created this one

(it also works on any screen resolution vs just iPhone 4/5/5s like the other example)

https://github.com/aubrey/SwiftPagingNav

class PageViewController: UIViewController, UIScrollViewDelegate {

var scrollView:UIScrollView!
var pageControl:UIPageControl!
var navbarView:UIView!

var navTitleLabel1:UILabel!
var navTitleLabel2:UILabel!
var navTitleLabel3:UILabel!

var view1:UIView!
var view2:UIView!
var view3:UIView!


override func viewDidLoad() {
    super.viewDidLoad()

    self.view.backgroundColor = UIColor.lightGrayColor()

    //Creating some shorthand for these values
    var wBounds = self.view.bounds.width
    var hBounds = self.view.bounds.height

    // This houses all of the UIViews / content
    scrollView = UIScrollView()
    scrollView.backgroundColor = UIColor.clearColor()
    scrollView.frame = self.view.frame
    scrollView.pagingEnabled = true
    scrollView.showsHorizontalScrollIndicator = false
    scrollView.delegate = self
    scrollView.bounces = false
    self.view.addSubview(scrollView)

    self.scrollView.contentSize = CGSize(width: self.view.bounds.size.width * 3, height: hBounds/2)

    //Putting a subview in the navigationbar to hold the titles and page dots
    navbarView = UIView()
    self.navigationController?.navigationBar.addSubview(navbarView)

    //Paging control is added to a subview in the uinavigationcontroller
    pageControl = UIPageControl()
    pageControl.frame = CGRect(x: 0, y: 35, width: 0, height: 0)
    pageControl.backgroundColor = UIColor.whiteColor()
    pageControl.numberOfPages = 3
    pageControl.currentPage = 0
    pageControl.currentPageIndicatorTintColor = UIColor(red:0.325, green:0.667, blue:0.922, alpha: 1)
    pageControl.pageIndicatorTintColor = UIColor.whiteColor()
    self.navbarView.addSubview(pageControl)


    //Titles for the nav controller (also added to a subview in the uinavigationcontroller)
    //Setting size for the titles. FYI changing width will break the paging fades/movement
    var titleSize = CGRect(x: 0, y: 8, width: wBounds, height: 20)

    navTitleLabel1 = UILabel()
    navTitleLabel1.frame = titleSize
    navTitleLabel1.text = "Home"
    navTitleLabel1.textAlignment = NSTextAlignment.Center
    self.navbarView.addSubview(navTitleLabel1)

    navTitleLabel2 = UILabel()
    navTitleLabel2.frame = titleSize
    navTitleLabel2.text = "Discover"
    navTitleLabel2.textAlignment = NSTextAlignment.Center
    self.navbarView.addSubview(navTitleLabel2)

    navTitleLabel3 = UILabel()
    navTitleLabel3.frame = titleSize
    navTitleLabel3.text = "Activity"
    navTitleLabel3.textAlignment = NSTextAlignment.Center
    self.navbarView.addSubview(navTitleLabel3)

    //Views for the scrolling view
    //This is where the content of your views goes (or you can subclass these and add them to ScrollView)

    view1 = UIView()
    view1.backgroundColor = UIColor(red:0.325, green:0.667, blue:0.922, alpha: 1)
    view1.frame = CGRectMake(0, 0, wBounds, hBounds)
    self.scrollView.addSubview(view1)
    self.scrollView.bringSubviewToFront(view1)

    //Notice the x position increases per number of views
    view2 = UIView()
    view2.backgroundColor = UIColor(red:0.231, green:0.529, blue:0.757, alpha: 1)
    view2.frame = CGRectMake(wBounds, 0, wBounds, hBounds)
    self.scrollView.addSubview(view2)
    self.scrollView.bringSubviewToFront(view2)

    //Notice the x position increases yet again (wBounds * 2)
    view3 = UIView()
    view3.backgroundColor = UIColor(red:0.529, green:0.600, blue:0.647, alpha: 1)
    view3.frame = CGRectMake(wBounds * 2, 0, wBounds, hBounds)
    self.scrollView.addSubview(view3)
    self.scrollView.bringSubviewToFront(view3)
}

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    navbarView.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 44)
}


func scrollViewDidScroll(scrollView: UIScrollView) {

    var xOffset: CGFloat = scrollView.contentOffset.x

    //Setup some math to position the elements where we need them when the view is scrolled

    var wBounds = self.view.bounds.width
    var hBounds = self.view.bounds.height
    var widthOffset = wBounds / 100
    var offsetPosition = 0 - xOffset/widthOffset

    //Apply the positioning values created above to the frame's position based on user's scroll

    navTitleLabel1.frame = CGRectMake(offsetPosition, 8, wBounds, 20)
    navTitleLabel2.frame = CGRectMake(offsetPosition + 100, 8, wBounds, 20)
    navTitleLabel3.frame = CGRectMake(offsetPosition + 200, 8, wBounds, 20)

    //Change the alpha values of the titles as they are scrolled

    navTitleLabel1.alpha = 1 - xOffset / wBounds

    if (xOffset <= wBounds) {
        navTitleLabel2.alpha = xOffset / wBounds
    } else {
        navTitleLabel2.alpha = 1 - (xOffset - wBounds) / wBounds
    }
    navTitleLabel3.alpha = (xOffset - wBounds) / wBounds


}


func scrollViewDidEndDecelerating(scrollView: UIScrollView) {

    var xOffset: CGFloat = scrollView.contentOffset.x

    //Change the pageControl dots depending on the page / offset values

    if (xOffset < 1.0) {
        pageControl.currentPage = 0
    } else if (xOffset < self.view.bounds.width + 1) {
        pageControl.currentPage = 1
    } else {
        pageControl.currentPage = 2
    }

}

}

like image 1
Aubrey Avatar answered Nov 10 '22 07:11

Aubrey