Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
cdc171a1
Unverified
Commit
cdc171a1
authored
Aug 28, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: added delegation method to PageTabBarController
parent
51c63666
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
10 deletions
+31
-10
Sources/iOS/PageTabBarController.swift
+23
-6
Sources/iOS/TabBar.swift
+8
-4
No files found.
Sources/iOS/PageTabBarController.swift
View file @
cdc171a1
...
...
@@ -44,6 +44,7 @@ open class PageTabBar: TabBar {
open
override
func
prepareView
()
{
super
.
prepareView
()
isLineAnimated
=
false
lineAlignment
=
.
top
}
}
...
...
@@ -88,7 +89,13 @@ extension UIViewController {
@objc(PageTabBarControllerDelegate)
public
protocol
PageTabBarControllerDelegate
{
/**
A delegation method that is executed when a UIViewController did transition to.
- Parameter pageTabBarController: A PageTabBarController.
- Parameter willTransitionTo viewController: A UIViewController.
*/
@objc
optional
func
pageTabBarController
(
pageTabBarController
:
PageTabBarController
,
didTransitionTo
viewController
:
UIViewController
)
}
@objc(PageTabBarController)
...
...
@@ -100,7 +107,7 @@ open class PageTabBarController: RootController {
open
internal(set)
var
selectedIndex
:
Int
=
0
/// PageTabBar alignment setting.
open
var
pageTabBarAlignment
=
PageTabBarAlignment
.
top
open
var
pageTabBarAlignment
=
PageTabBarAlignment
.
bottom
/// Reference to the PageTabBar.
open
internal(set)
var
pageTabBar
:
PageTabBar
!
...
...
@@ -228,11 +235,14 @@ open class PageTabBarController: RootController {
isTabSelectedAnimation
=
true
selectedIndex
=
index
pageTabBar
.
select
(
at
:
selectedIndex
)
setViewControllers
([
viewControllers
[
index
]],
direction
:
direction
,
animated
:
true
)
{
[
weak
self
]
_
in
guard
let
s
=
self
else
{
return
}
s
.
isTabSelectedAnimation
=
false
s
.
delegate
?
.
pageTabBarController
?(
pageTabBarController
:
s
,
didTransitionTo
:
s
.
viewControllers
[
s
.
selectedIndex
])
}
}
...
...
@@ -266,6 +276,10 @@ extension PageTabBarController: UIPageViewControllerDelegate {
selectedIndex
=
index
pageTabBar
.
select
(
at
:
selectedIndex
)
if
finished
&&
completed
{
delegate
?
.
pageTabBarController
?(
pageTabBarController
:
self
,
didTransitionTo
:
v
)
}
}
}
...
...
@@ -301,12 +315,11 @@ extension PageTabBarController: UIPageViewControllerDataSource {
extension
PageTabBarController
:
UIScrollViewDelegate
{
public
func
scrollViewDidScroll
(
_
scrollView
:
UIScrollView
)
{
guard
!
isTabSelectedAnimation
else
{
pageTabBar
.
select
(
at
:
selectedIndex
)
guard
!
pageTabBar
.
isAnimating
else
{
return
}
guard
0
<
view
.
width
else
{
guard
!
isTabSelectedAnimation
else
{
return
}
...
...
@@ -314,8 +327,12 @@ extension PageTabBarController: UIScrollViewDelegate {
return
}
guard
0
<
view
.
width
else
{
return
}
let
x
=
(
scrollView
.
contentOffset
.
x
-
view
.
width
)
/
scrollView
.
contentSize
.
width
*
view
.
width
pageTabBar
.
line
.
x
=
selected
.
x
+
x
// - (0 < selectedIndex ? pageTabBar.grid.interimSpace * CGFloat(selectedIndex - 1) : 0)
pageTabBar
.
line
.
center
.
x
=
selected
.
center
.
x
+
x
}
}
Sources/iOS/TabBar.swift
View file @
cdc171a1
...
...
@@ -58,6 +58,9 @@ public protocol TabBarDelegate {
}
open
class
TabBar
:
View
{
/// A boolean indicating if the TabBar line is in an animation state.
open
internal(set)
var
isAnimating
=
false
/// Will render the view.
open
var
willRenderView
:
Bool
{
return
0
<
width
&&
0
<
height
&&
nil
!=
superview
...
...
@@ -222,17 +225,18 @@ open class TabBar: View {
open
func
animate
(
to
button
:
UIButton
,
completion
:
(
@escaping
(
UIButton
)
->
Void
)?
=
nil
)
{
delegate
?
.
tabBarWillSelectButton
?(
tabBar
:
self
,
button
:
button
)
selected
=
button
isAnimating
=
true
UIView
.
animate
(
withDuration
:
0.25
,
animations
:
{
[
weak
self
,
button
=
button
]
in
guard
let
s
=
self
else
{
return
}
s
.
line
.
x
=
button
.
x
s
.
line
.
center
.
x
=
button
.
center
.
x
s
.
line
.
width
=
button
.
width
})
{
[
weak
self
,
button
=
button
,
completion
=
completion
]
_
in
guard
let
s
=
self
else
{
return
}
s
.
isAnimating
=
false
s
.
delegate
?
.
tabBarDidSelectButton
?(
tabBar
:
s
,
button
:
button
)
completion
?(
button
)
}
...
...
@@ -247,8 +251,7 @@ open class TabBar: View {
*/
open
override
func
prepareView
()
{
super
.
prepareView
()
interimSpacePreset
=
.
none
contentEdgeInsetsPreset
=
.
none
autoresizingMask
=
.
flexibleWidth
prepareLine
()
prepareDivider
()
...
...
@@ -266,6 +269,7 @@ open class TabBar: View {
/// Prepares the divider.
private
func
prepareDivider
()
{
divider
=
Divider
(
view
:
self
)
divider
.
alignment
=
.
top
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment