Code Monkey home page Code Monkey logo

aafragmentmanager's Introduction

Table of Contents

#AAFragmentManager

Swift 4.0 Carthage compatible CocoaPods License MIT Build Status License MIT CocoaPods

##Description

AAFragmentManager is a child view manager responsible to add child subviews in UIView, designed for easy switching between child view controllers with animations.

##Demonstration

To run the example project, clone the repo, and run pod install from the Example directory first.

##Requirements

  • iOS 8.0+
  • Xcode 8.0+

Installation

AAFragmentManager can be installed using CocoaPods, Carthage, or manually.

##CocoaPods

AAFragmentManager is available through CocoaPods. To install CocoaPods, run:

$ gem install cocoapods

Then create a Podfile with the following contents:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
pod 'AAFragmentManager', '~> 2.0'
end

Finally, run the following command to install it:

$ pod install

##Carthage

To install Carthage, run (using Homebrew):

$ brew update
$ brew install carthage

Then add the following line to your Cartfile:

github "EngrAhsanAli/AAFragmentManager" "master"

Then import the library in all files where you use it:

import AAFragmentManager

##Manual Installation

If you prefer not to use either of the above mentioned dependency managers, you can integrate AAFragmentManager into your project manually by adding the files contained in the Classes folder to your project.

#Getting Started

##Create your fragment manager

Create a UIView and set the class as AAFragmentManager. Make an IBOutlet of that view.

@IBOutlet weak var childView: AAFragmentManager!

// Customize the replace animations with the instance
childView.nextTransition = kCATransitionFromTop
childView.prevTransition = kCATransitionFromBottom

You need to set all child views identifiers and make a UIViewController array to pass AAFragmentManager

##Setup your child views

Get child view controllers with in specific storyboard as follow:

let vcs = AAFragmentManager.getViewControllers(withIds: #Array_of_Identifiers#, storyboard: #Storyboard_Name#)

You can init the AAFragmentManager with the array of UIViewController

childView.initManager(viewControllers: #Array_of_ViewController#)

You can init the AAFragmentManager with the array of UIViewController providing the parent view controller instance and identifier to call it where ever you like!

extension AAFragmentManager {
    static let instance_1 = AAFragmentManagerInstance("SampleIdentifier")
}

childView.initManager(viewControllers: #Array_of_ViewController#, parentViewController: #Parent_View_Controller#, identifier: #Instance_ID_String#)

You can init the AAFragmentManager with the array of AAFragment

extension AAFragmentManager {
    static let id_frag_1 = AAFragment("ChlidVC1", storyboard: "Main")
    static let id_frag_2 = AAFragment("ChlidVC2", storyboard: "Main")
}

childView.initManager(fragments: #Array_of_AAFragment#)

You can init the AAFragmentManager with the array of AAFragment providing the parent view controller instance and identifier to call it where ever you like!

extension AAFragmentManager {
    static let instance_1 = AAFragmentManagerInstance("SampleIdentifier")
}

childView.initManager(fragments: #Array_of_AAFragment#, parentViewController: #Parent_View_Controller#, identifier: #Instance_ID_String#)

##Get any child views controller

You can get any child view controller by accessing it through index

let demoFragment = childView.getFragment(withIndex: 0) as! Fragment1
demoFragment.delegate = self // sets for some callback

You can get any child view controller by accessing it through AAFragment

extension AAFragmentManager {
    static let id_frag_1 = AAFragment("ChlidVC1", storyboard: "Main")
}

let demoFragment = childView.getFragment(fragment: #AAFragment#) as! Fragment1
demoFragment.delegate = self // sets for some callback

You can get the static instance anywhere if required

extension AAFragmentManager {
    static let id_frag_1 = AAFragment("ChlidVC1", storyboard: "Main")
    static let vc_frag_1 = id_frag_1.viewsController as! Fragment1
}

AAFragmentManager.vc_frag_1.clickAction(self)

Note that getFragment method can return nil if any invalid index passed.

##Switching between child views

You can switch child view controllers with next() and previous() methods safely!

// replace with next fragment
childView.previous()
// replace with previous fragment
childView.next()

You can switch child view controllers using the single line

// replace fragment by index
    childView.replace(withIndex: index)

// replace fragment by AAFragment
    childView.replace(withfragment: .id_frag_1)

Get the instance of any AAFragmentManager with a static method

extension AAFragmentManager {
    static let instance_1 = AAFragmentManagerInstance("SampleIdentifier")
}

// Get the instance
let manager = AAFragmentManager.getInstance(withIdentifier: .instance_1)

// Gets the parent view controller instance
let parent = manager.parentViewController

#Contributions & License

AAFragmentManager is available under the MIT license. See the LICENSE file for more info.

Pull requests are welcome! The best contributions will consist of substitutions or configurations for classes/methods known to block the main thread during a typical app lifecycle.

I would love to know if you are using AAFragmentManager in your app, send an email to Engr. Ahsan Ali

aafragmentmanager's People

Contributors

engrahsanali 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.