Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions AMTabView/Classes/AMTabsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ open class AMTabsViewController: UIViewController {
}

let currentView = containerView.subviews.first
currentView?.removeFromSuperview()

let contoller = children[index]
let newView = contoller.view
let controller = children[index]
let newView = controller.view
if newView?.superview == nil {
containerView.addSubview(newView!)
contoller.didMove(toParent: self)
controller.didMove(toParent: self)
newView?.frame = containerView.bounds

doTransition(fromController: viewControllers![lastSelectedViewIndex ?? 0], toController: viewControllers![index], currentView: currentView, animate: true)
}

lastSelectedViewIndex = index
Expand Down Expand Up @@ -186,3 +187,23 @@ extension AMTabsViewController: AMTabViewDelegate {
}

}


///
/// Do the transition from current view to the target view. Allows to choose if the transition is animated or not.
///
func doTransition(fromController: UIViewController?, toController: UIViewController?,currentView: UIView?, animate: Bool){

guard let fromView = fromController?.view, let toView = toController?.view else {
return
}

if animate {
if fromView != toView {
UIView.transition(from: fromView, to: toView, duration: 0.3, options: [.transitionFlipFromLeft], completion: nil)
}
}else{
currentView?.removeFromSuperview()
}

}