/AAFragmentManager

AAFragmentManager is a child view manager responsible to add child subviews in UIView and easy switching between them, written in Swift.

Primary LanguageShellMIT LicenseMIT

Table of Contents

#AAFragmentManager

Swift 3.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', :git => 'https://github.com/mengheangrat/AAFragmentManager.git'
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" 

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!

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

##Setup your child views

Now create child views (fragments) using single line

childView.setupFragments(arrayVC, defaultIndex: 0)

Note that defaultIndex is for first initial child view that will be automatically added by the AAFragmentManager. defaultIndex is optional parameter.

##Get any child views controller

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

let demoFragment = childView.getFragment(0)
demoFragment.delegate = self // sets for some callback

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

##Switching between child views

You can switch child view controllers using the single line

childView.replaceFragment(index: 1)

Note that replaceFragment has optional parameters shouldAnimate , shouldFit, allowSameFragment.

Here's the method signature

open func replaceFragment(index: Int, shouldAnimate animate: Bool = true, shouldFit fit: Bool = true, allowSameFragment sameFragment: Bool = false)

By default, shouldFit is true such that it will make fragment of same height as its parent view and vice versa.

#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