Table of Contents
#AAFragmentManager
##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 passAAFragmentManager
##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 returnnil
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