-1

How can I create a navigation Bar that will cycle through 3 Views and will scale the view's icon just like Tinder's? http://i3.mirror.co.uk/news/technology-science/technology/article6812543.ece/ALTERNATES/s615b/Tinder-update.jpg

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • You need to subclass the `UINavigationBar`. This will take lot of code to put it here. – Sachin Vas Oct 19 '16 at 14:39
  • There's nothing special about the navigation bar in the pictures. Just do what you would normally do: use a navigation controller, and each child view controller sets its own `navigationItem` properties. – matt Oct 20 '16 at 16:26

1 Answers1

2

This Framework provides the exact Navbar like Tinder and is for Swift 2.

pod 'SLPagingViewSwift'

Easy to implement:

// Make views for the navigation bar
var img1 = UIImage(named: "gear")
img1 = img1?.imageWithRenderingMode(.AlwaysTemplate)
var img2 = UIImage(named: "profile")
img2 = img2?.imageWithRenderingMode(.AlwaysTemplate)
var img3 = UIImage(named: "chat")
img3 = img3?.imageWithRenderingMode(.AlwaysTemplate)

var items = [UIImageView(image: img1), UIImageView(image: img2), UIImageView(image: img3)]
var controllers = [ctr1, ctr2, ctr3]
controller = SLPagingViewSwift(items: items, controllers: controllers, showPageControl: false)

Then you can make your own behaviors:

// Tinder Like
controller?.pagingViewMoving = ({ subviews in
    for v in subviews {
        var lbl = v as UIImageView
        var c = gray

        if(lbl.frame.origin.x > 45 && lbl.frame.origin.x < 145) {
            c = self.gradient(Double(lbl.frame.origin.x), topX: Double(46), bottomX: Double(144), initC: orange, goal: gray)
        }
        else if (lbl.frame.origin.x > 145 && lbl.frame.origin.x < 245) {
            c = self.gradient(Double(lbl.frame.origin.x), topX: Double(146), bottomX: Double(244), initC: gray, goal: orange)
        }
        else if(lbl.frame.origin.x == 145){
            c = orange
        }
        lbl.tintColor = c
    }
})

For further spectators: I have forked the Framework and updated it to Swift 3.

SLPagingViewSwift Swift 3

To install my fork:

pod 'SLPagingViewSwift-Swift3', :git => 'https://github.com/davidseek/SLPagingViewSwift-Swift-3-Tinder-Twitter.git'

enter image description here

Edit

To build your UI with the Interface Builder, you have to set your UIViewController als global objects, otherwise TableViews will use the delegates because of a weak property. Create a Swift file and enter the names of your controllers:

var one: ViewControllerOne?
var two: ViewControllerTwo?
var three: ViewControllerThree?

Then you instantiate the controllers in your controller class or AppDelegate and call everything:

func load() {
    appDelegate.window = UIWindow(frame: UIScreen.main.bounds)

    self.setupViews()
    self.setItems()

    let items = [UIImageView(image: bla),
                 UIImageView(image: bli),
                 UIImageView(image: blubb)]

    let controllers = [one!,
                       two!,
                       three!]

    controller = SLPagingViewSwift(items: items, controllers: controllers, showPageControl: false)

    self.setupController() 
    self.setRoot()
}

func setupViews()  {
    one = main.instantiateViewController(withIdentifier: "ViewControllerOne") as? ViewControllerOne
    two = main.instantiateViewController(withIdentifier: "ViewControllerTwo") as? ViewControllerTwo
    three = main.instantiateViewController(withIdentifier: "ViewControllerThree") as? ViewControllerThree
}

func setRoot() {
    nav = UINavigationController(rootViewController: controller)
    appDelegate.window?.rootViewController = nav
    appDelegate.window?.backgroundColor = UIColor.black
    appDelegate.window?.makeKeyAndVisible()
}

func setupController() {
    controller.pagingViewMoving = ({ subviews in
        if let imageViews = subviews as? [UIImageView] {
            for imgView in imageViews {
                var c = cachedGray
                let originX = Double(imgView.frame.origin.x)

                if (originX > 95 && originX < 195) {
                    c = gradient(originX, topX: 96, bottomX: 194, initC: cachedOrange, goal: cachedGray)
                }
                else if (originX > 195 && originX < 245) {
                    c = gradient(originX, topX: 196, bottomX: 294, initC: cachedGray, goal: cachedOrange)
                }
                else if(originX == 195){
                    c = cachedOrange
                }
                imgView.tintColor = c
            }
        }
    })
}

In my example you could use an empty view as initial view controller at the storyboard and call load() in the viewDidLoad(). Then your controller would be loaded.

Here is a working test project with Tinder style and 3 ViewControllers from Storyboard

David Seek
  • 16,783
  • 19
  • 105
  • 136
  • Thanks for the work @DavidSeek Looks amazing. but does it mean that you cannot use main.storyboard view controllers to design the rest of the UI elements? i will have to do it all programmatically ? – Eyal Ben Yehuda Oct 24 '16 at 23:29
  • you can. i'm currently using it in a project. i will add a comment to my answer to show you how – David Seek Oct 24 '16 at 23:30
  • 1
    Hi @DavidSeek i'm trying now (just starting) to use it. notice the pod line here is a bit different (and not working) from the one in your instructions on github (that works). – Eyal Ben Yehuda Oct 26 '16 at 21:09
  • edited. thank you for the hint. i have updated the pod in the meantime – David Seek Oct 26 '16 at 21:12
  • So as a newbie.. i see it’s kind of hard for me. really tried but it is very confusing to me. also stumbling some errors... it will be amazing if you will have the chance to create and share the simplest sample project where it have 3 view controllers on the main.storyboard UI and that each VC have his UI View controller class file. I really want to use it and i hope it’s not too much to ask:) – Eyal Ben Yehuda Oct 26 '16 at 22:54
  • don't forget to start the project with the `white icon`, the `TinderTest.xcworkspace`, since the project uses cocoapods – David Seek Oct 26 '16 at 23:24
  • Hi @DavidSeek, i managed to add a UI navigation controller to the UI builder and link it to nav. i also set the initial page to the middle one. the only problem i currently have is that i don't have control on the segues. i added in the 3 view controllers "override func prepare(for segue: UIStoryboardSegue, sender: Any?)" to print the segue.identifier but it is never hitting this method. i need it to pass data between view controllers. how would you do it? thanks. – Eyal Ben Yehuda yesterday – Eyal Ben Yehuda Oct 31 '16 at 08:39
  • Additionally, how would you implement a segue from one view controller to another by tapping an element (like a button)? if i set a regular segue, using a button, from one VC to another - it shows the target VC without the navigation bar. – Eyal Ben Yehuda Oct 31 '16 at 08:39
  • the issue here is, that the `nav` is not a `UINavigationController`, but a `UIViewController`. you need to push the view controllers and those view controllers need their own navigation bar with a back button that dismisses the views. – David Seek Oct 31 '16 at 14:50
  • if you have further problems, please open up new threads here on stackoverflow and post your code. helping you with 1-2 sentences is too weird. if you have opened a new thread, feel free to post the link in here – David Seek Oct 31 '16 at 14:52
  • Hi @DavidSeek. but i saw this line of code in Global.swift: "var nav: UINavigationController?" so i assumed it is a UINavigationController. isn't it? anyway, i used your advice: http://stackoverflow.com/questions/40350010/tinder-like-navigation-in-swift Thanks. – Eyal Ben Yehuda Oct 31 '16 at 20:29
  • Hi @DavidSeek or other viewers. i posted a related question with a sample project with the issue here: http://stackoverflow.com/questions/40428075/segue-from-a-slpagingviewswift-vc-and-dismiss-the-destination-vc-to-return i can't find how to implemented the solutions i found in my context (SLPagingView). i would appreciate it a lot if someone can take a look and help, Thanks! – Eyal Ben Yehuda Nov 08 '16 at 16:20
  • @DavidSeek hiii could u help me with this type of UI inside top navigation bar with swipe viewcontroller https://stackoverflow.com/questions/51281675/how-to-create-top-navigation-like-reddit-app-in-swift-3 – Dilip Tiwari Jul 12 '18 at 09:43
  • @DilipTiwari it's the same idea as here. you need to create the view yourself just like i did here – David Seek Jul 12 '18 at 15:36
  • could u provide me solution for that question @DavidSeek – Dilip Tiwari Jul 12 '18 at 18:50
  • It's way too broad. There is no easy answer and here you're looking for someone to do the code for you. All I can to at this point is to point you into the right direction. If you can't figure it out, then you need to hire someone for a couple hours who does it for you. – David Seek Jul 12 '18 at 20:54