Commit 4ff9db52 by Orkhan Alikhanov

Added interactive line transition methods for tabBar

parent cbd13228
......@@ -29,6 +29,7 @@
*/
import UIKit
import Motion
open class TabItem: FlatButton {
/// A dictionary of TabItemStates to UIColors for states.
......@@ -574,6 +575,55 @@ extension TabBar {
}
}
internal extension TabBar {
/**
Starts line transition for the index with the given duration.
- Parameter for index: An Int.
- Parameter duration: A TimeInterval.
*/
func startLineTransition(for index: Int, duration: TimeInterval = 0.35) {
guard let s = selectedTabItem, let currentIndex = tabItems.firstIndex(of: s) else {
return
}
guard currentIndex != index else {
return
}
let targetFrame = lineFrame(for: tabItems[index], forMotion: true)
line.transition(.size(targetFrame.size),
.position(targetFrame.origin),
.duration(duration))
line.motionViewTransition.start()
}
/**
Updates line transition to the given progress value.
- Parameter _ progress: A CGFloat.
*/
func updateLineTransition(_ progress: CGFloat) {
line.motionViewTransition.update(progress)
}
/**
Finishes line transition.
- Parameter isAnimated: A Boolean indicating if the change should be animated.
*/
func finishLineTransition(isAnimated: Bool = true) {
line.motionViewTransition.finish(isAnimated: isAnimated)
}
/**
Cancels line transition.
- Parameter isAnimated: A Boolean indicating if the change should be animated.
*/
func cancelLineTransition(isAnimated: Bool = true) {
line.motionViewTransition.cancel(isAnimated: isAnimated)
}
}
fileprivate extension TabBar {
/**
Removes the tabItem animation handler.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment