Commit d75ed300 by Daniel Dahan

initial scrollable TabBar work added

parent 0c526c8f
......@@ -105,7 +105,7 @@ open class Bar: View {
}
/// ContentView that holds the any desired subviews.
open let contentView = UIView()
open let contentView = UIScrollView()
/// Left side UIViews.
open var leftViews: [UIView] {
......@@ -272,5 +272,17 @@ open class Bar: View {
autoresizingMask = .flexibleWidth
interimSpacePreset = .interimSpace3
contentEdgeInsetsPreset = .square1
prepareContentView()
}
}
extension Bar {
/// Prepares the contentView.
fileprivate func prepareContentView() {
contentView.bounces = false
contentView.isPagingEnabled = true
contentView.showsVerticalScrollIndicator = false
contentView.showsHorizontalScrollIndicator = false
contentView.contentScaleFactor = Screen.scale
}
}
......@@ -196,6 +196,7 @@ open class PageMenuController: UIViewController {
when subclassing.
*/
open func prepare() {
view.contentScaleFactor = Screen.scale
prepareScrollView()
prepareViewControllers()
}
......@@ -209,6 +210,7 @@ extension PageMenuController {
scrollView.isPagingEnabled = true
scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false
scrollView.contentScaleFactor = Screen.scale
view.addSubview(scrollView)
}
......@@ -287,6 +289,7 @@ extension PageMenuController {
tabBar?.isLineAnimated = false
tabBar?.lineAlignment = .top
view.addSubview(tabBar!)
prepareTabBarButtons(buttons)
}
......@@ -350,10 +353,6 @@ extension PageMenuController {
- Parameter position: An Int for the position of the view controller.
*/
fileprivate func layoutViewController(at index: Int, position: Int) {
guard 0 <= index && index < viewControllers.count else {
return
}
viewControllers[index].view.frame = CGRect(x: CGFloat(position) * scrollView.width, y: 0, width: scrollView.width, height: scrollView.height)
}
}
......
......@@ -57,10 +57,33 @@ public protocol TabBarDelegate {
optional func tabBar(tabBar: TabBar, didSelect button: UIButton)
}
@objc(TabBarStyle)
public enum TabBarStyle: Int {
case normal
case scrollable
}
open class TabBar: Bar {
/// A boolean indicating if the TabBar line is in an animation state.
open internal(set) var isAnimating = false
/// Enables and disables bouncing when swiping.
open var isBounceEnabled: Bool {
get {
return contentView.bounces
}
set(value) {
contentView.bounces = value
}
}
/// An enum that determines the tab bar style.
open var tabBarStyle = TabBarStyle.scrollable {
didSet {
layoutSubviews()
}
}
/// A delegation reference.
open weak var delegate: TabBarDelegate?
......@@ -116,8 +139,6 @@ open class TabBar: Bar {
b.removeFromSuperview()
}
centerViews = buttons as [UIView]
layoutSubviews()
}
}
......@@ -186,8 +207,25 @@ open class TabBar: Bar {
}
}
if .scrollable == tabBarStyle {
var w: CGFloat = 0
for b in buttons {
let width = b.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: contentView.height)).width + interimSpace
contentView.addSubview(b)
b.height = contentView.height
b.width = width
b.x = w
w += width
}
print(w, contentView.width)
if w > contentView.width {
contentView.contentSize.width = w
}
} else {
contentView.grid.axis.columns = buttons.count
contentView.grid.reload()
centerViews = buttons
}
if nil == selected {
selected = buttons.first
......@@ -205,8 +243,9 @@ open class TabBar: Bar {
*/
open override func prepare() {
super.prepare()
isBounceEnabled = true
contentEdgeInsetsPreset = .none
interimSpacePreset = .none
interimSpacePreset = .interimSpace5
prepareLine()
prepareDivider()
}
......
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