Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Ramotion/animated-tab-bar
Browse files Browse the repository at this point in the history
  • Loading branch information
0ber committed Jun 13, 2019
2 parents d7d08b2 + 3fc716a commit 2f54635
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@ extension RAMAnimatedTabBarController {

func createBottomLine() {
guard let currentItem = (containers.filter { $0.value.tag == 0 }).first?.value else { return }

let lineHeight: CGFloat = 2

let container = UIView()
container.backgroundColor = .clear
container.translatesAutoresizingMaskIntoConstraints = false

view.addSubview(container)

container.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
container.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
container.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
container.heightAnchor.constraint(equalToConstant: lineHeight).isActive = true
container.heightAnchor.constraint(equalToConstant: bottomLineHeight).isActive = true


let line = UIView()
Expand All @@ -48,10 +46,12 @@ extension RAMAnimatedTabBarController {

lineLeadingConstraint = bottomLine?.leadingAnchor.constraint(equalTo: currentItem.leadingAnchor)
lineLeadingConstraint?.isActive = true


lineHeightConstraint = bottomLine?.heightAnchor.constraint(equalToConstant: bottomLineHeight)
lineHeightConstraint?.isActive = true

// add constraints
bottomLine?.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
bottomLine?.heightAnchor.constraint(equalToConstant: lineHeight).isActive = true
bottomLine?.widthAnchor.constraint(equalTo: currentItem.widthAnchor).isActive = true
}

Expand Down Expand Up @@ -79,4 +79,11 @@ extension RAMAnimatedTabBarController {
self.bottomLine?.superview?.layoutIfNeeded()
}
}

func updateBottomLineHeight(to height: CGFloat) {
lineHeightConstraint?.isActive = false

lineHeightConstraint = bottomLine?.heightAnchor.constraint(equalToConstant: height)
lineHeightConstraint?.isActive = true
}
}
12 changes: 12 additions & 0 deletions RAMAnimatedTabBarController/RAMAnimatedTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ open class RAMAnimatedTabBarController: UITabBarController {
}
}

/**
Bottom line height
**/
open var bottomLineHeight: CGFloat = 2 {
didSet {
if bottomLineHeight > 0 {
updateBottomLineHeight(to: bottomLineHeight)
}
}
}

/**
Bottom line time of animations duration
**/
Expand All @@ -253,6 +264,7 @@ open class RAMAnimatedTabBarController: UITabBarController {
}
}

var lineHeightConstraint: NSLayoutConstraint?
var lineLeadingConstraint: NSLayoutConstraint?
var bottomLine: UIView?
var arrBottomAnchor:[NSLayoutConstraint] = []
Expand Down

0 comments on commit 2f54635

Please sign in to comment.