Giter Club home page Giter Club logo

uipageviewcontrollerpart1's Introduction

EVERYTHING ABOUT PAGEVIEWCONTROLLERS.

PART 1


Background

This repository documents Part 1 of the multi-part series that implements exhaustive and in-depth concepts about PageViewControllers in iOS.


Repository Specification

Details about UIPageViewController for this Part

  • Transition Style is Page Curl (Interface builder)
  • Double sided propery is false (Interface builder)
  • Spine location can be min or max (Interface builder)
  • Delegate and Data Source are nil
  • Gesture based navigation is not included
  • Total of 6 View Controllers for this example
  • Storyboard IDs in Interface Builder

How to Use

The document has useful content in Main storyboard file and in MainPageViewController.swift file.
Below is the implementation that is used to provide content to PageViewController.


import UIKit

class MainPageViewController: UIPageViewController {
    
    var currentPageIndexForMinMaxSpine = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        setupMinMaxSpinePageSet()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

/**** ****                                  **** ****
 *  If spine location setting is Min or Max and double sided property is set to false
 *  The above mentioned properties can be setup from Interface Builder. UIPageViewController object's Attributes inspector
 **** ****                                 **** ****/
extension MainPageViewController {
    
    fileprivate func setupMinMaxSpinePageSet() {
        setupViewControllersMinMaxSpine(pageIndex: currentPageIndexForMinMaxSpine)
        
        let minmaxSpineTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(minmaxSpinePageTapped))
        self.view.addGestureRecognizer(minmaxSpineTapGestureRecognizer)
    }
    
    fileprivate func setupViewControllersMinMaxSpine(pageIndex: Int) {
        self.view.isUserInteractionEnabled = false
        
        if pageIndex == GlobalSetup.contentViewControllers.count {
            self.currentPageIndexForMinMaxSpine = 0
            setViewControllers([GlobalSetup.contentViewControllers[0]], direction: .forward, animated: true, completion: {
                print("The success status is: \($0), We are on Page number \(self.currentPageIndexForMinMaxSpine + 1)")
                self.view.isUserInteractionEnabled = true
            })
        } else {
            setViewControllers([GlobalSetup.contentViewControllers[pageIndex]], direction: .forward, animated: true, completion: {
                print("The success status is: \($0), We are on Page number \(pageIndex + 1)")
                self.view.isUserInteractionEnabled = true
            })
        }
    }
    
    @objc func minmaxSpinePageTapped() {
        currentPageIndexForMinMaxSpine += 1
        setupViewControllersMinMaxSpine(pageIndex: currentPageIndexForMinMaxSpine)
    }
    
}


struct GlobalSetup {
    
    static func getViewController(id: String) -> UIViewController! {
        return UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: id)
    }
    
    static var contentViewControllers = {
        return ["MyFirstViewController", "MySecondViewController", "MyThirdViewController", "MyFourthViewController", "MyFifthViewController", "MySixthViewController"].map({getViewController(id: $0)!})
    }()
    
}

Note

The implementation and content providing using dataSource will be implemented in future part of this series.


uipageviewcontrollerpart1's People

Contributors

athakur3 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.