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
6554f20e
Unverified
Commit
6554f20e
authored
Aug 25, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: fixed grid issue, where views were causing an out of bounds index error
parent
8363fcbd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
29 deletions
+86
-29
Sources/iOS/ControlView.swift
+2
-22
Sources/iOS/Grid.swift
+8
-6
Sources/iOS/PageController.swift
+53
-0
Sources/iOS/TabBar.swift
+23
-1
No files found.
Sources/iOS/ControlView.swift
View file @
6554f20e
...
@@ -91,29 +91,15 @@ open class ControlView: View {
...
@@ -91,29 +91,15 @@ open class ControlView: View {
open
private(set)
var
contentView
:
View
!
open
private(set)
var
contentView
:
View
!
/// Left side UIControls.
/// Left side UIControls.
open
var
leftControls
:
[
UIView
]
{
open
var
leftControls
=
[
UIView
]()
{
didSet
{
didSet
{
for
v
in
oldValue
{
v
.
removeFromSuperview
()
}
for
v
in
leftControls
{
addSubview
(
v
)
}
layoutSubviews
()
layoutSubviews
()
}
}
}
}
/// Right side UIControls.
/// Right side UIControls.
open
var
rightControls
:
[
UIView
]
{
open
var
rightControls
=
[
UIView
]()
{
didSet
{
didSet
{
for
v
in
oldValue
{
v
.
removeFromSuperview
()
}
for
v
in
rightControls
{
addSubview
(
v
)
}
layoutSubviews
()
layoutSubviews
()
}
}
}
}
...
@@ -123,8 +109,6 @@ open class ControlView: View {
...
@@ -123,8 +109,6 @@ open class ControlView: View {
- Parameter aDecoder: A NSCoder instance.
- Parameter aDecoder: A NSCoder instance.
*/
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
leftControls
=
[]
rightControls
=
[]
super
.
init
(
coder
:
aDecoder
)
super
.
init
(
coder
:
aDecoder
)
}
}
...
@@ -135,15 +119,11 @@ open class ControlView: View {
...
@@ -135,15 +119,11 @@ open class ControlView: View {
- Parameter frame: A CGRect instance.
- Parameter frame: A CGRect instance.
*/
*/
public
override
init
(
frame
:
CGRect
)
{
public
override
init
(
frame
:
CGRect
)
{
leftControls
=
[]
rightControls
=
[]
super
.
init
(
frame
:
frame
)
super
.
init
(
frame
:
frame
)
}
}
/// Basic initializer.
/// Basic initializer.
public
init
()
{
public
init
()
{
leftControls
=
[]
rightControls
=
[]
super
.
init
(
frame
:
.
zero
)
super
.
init
(
frame
:
.
zero
)
frame
.
size
=
intrinsicContentSize
frame
.
size
=
intrinsicContentSize
}
}
...
...
Sources/iOS/Grid.swift
View file @
6554f20e
...
@@ -173,7 +173,7 @@ public class Grid {
...
@@ -173,7 +173,7 @@ public class Grid {
}
}
/// An Array of UIButtons.
/// An Array of UIButtons.
public
var
views
:
[
UIView
]
{
public
var
views
=
[
UIView
]()
{
didSet
{
didSet
{
reload
()
reload
()
}
}
...
@@ -190,7 +190,6 @@ public class Grid {
...
@@ -190,7 +190,6 @@ public class Grid {
self
.
rows
=
rows
self
.
rows
=
rows
self
.
columns
=
columns
self
.
columns
=
columns
self
.
interimSpace
=
interimSpace
self
.
interimSpace
=
interimSpace
views
=
[
UIView
]()
offset
=
GridOffset
(
grid
:
self
)
offset
=
GridOffset
(
grid
:
self
)
axis
=
GridAxis
(
grid
:
self
)
axis
=
GridAxis
(
grid
:
self
)
}
}
...
@@ -198,11 +197,13 @@ public class Grid {
...
@@ -198,11 +197,13 @@ public class Grid {
/// Reload the button layout.
/// Reload the button layout.
public
func
reload
()
{
public
func
reload
()
{
var
n
:
Int
=
0
var
n
:
Int
=
0
var
i
:
Int
=
0
for
i
in
0
..<
views
.
count
{
for
child
in
views
{
let
child
=
views
[
i
]
guard
let
parent
=
context
else
{
return
}
if
let
parent
=
context
{
if
parent
!=
child
.
superview
{
if
parent
!=
child
.
superview
{
child
.
removeFromSuperview
()
child
.
removeFromSuperview
()
parent
.
addSubview
(
child
)
parent
.
addSubview
(
child
)
...
@@ -248,7 +249,8 @@ public class Grid {
...
@@ -248,7 +249,8 @@ public class Grid {
child
.
width
=
w
*
CGFloat
(
c
)
-
interimSpace
child
.
width
=
w
*
CGFloat
(
c
)
-
interimSpace
child
.
height
=
h
*
CGFloat
(
r
)
-
interimSpace
child
.
height
=
h
*
CGFloat
(
r
)
-
interimSpace
}
}
}
i
+=
1
}
}
}
}
}
}
...
...
Sources/iOS/PageController.swift
View file @
6554f20e
...
@@ -55,6 +55,9 @@ public protocol PageControllerDelegate {
...
@@ -55,6 +55,9 @@ public protocol PageControllerDelegate {
@objc(PageController)
@objc(PageController)
open
class
PageController
:
RootController
{
open
class
PageController
:
RootController
{
/// A boolean that indicates when a button animation is active.
internal
var
animating
=
false
/// The currently selected UIViewController.
/// The currently selected UIViewController.
open
internal(set)
var
selectedIndex
:
Int
=
0
open
internal(set)
var
selectedIndex
:
Int
=
0
...
@@ -137,6 +140,12 @@ open class PageController: RootController {
...
@@ -137,6 +140,12 @@ open class PageController: RootController {
v
.
delegate
=
self
v
.
delegate
=
self
v
.
dataSource
=
self
v
.
dataSource
=
self
v
.
isDoubleSided
=
false
v
.
isDoubleSided
=
false
for
view
in
v
.
view
.
subviews
{
if
view
.
isKind
(
of
:
UIScrollView
.
self
)
{
(
view
as?
UIScrollView
)?
.
delegate
=
self
}
}
}
}
/// Prepares the tabBar.
/// Prepares the tabBar.
...
@@ -145,6 +154,7 @@ open class PageController: RootController {
...
@@ -145,6 +154,7 @@ open class PageController: RootController {
tabBar
=
TabBar
()
tabBar
=
TabBar
()
tabBar
.
zPosition
=
1000
tabBar
.
zPosition
=
1000
view
.
addSubview
(
tabBar
)
view
.
addSubview
(
tabBar
)
tabBar
.
select
(
at
:
selectedIndex
)
}
}
}
}
}
}
...
@@ -157,7 +167,25 @@ extension PageController {
...
@@ -157,7 +167,25 @@ extension PageController {
}
}
extension
PageController
:
UIPageViewControllerDelegate
{
extension
PageController
:
UIPageViewControllerDelegate
{
public
func
pageViewController
(
_
pageViewController
:
UIPageViewController
,
didFinishAnimating
finished
:
Bool
,
previousViewControllers
:
[
UIViewController
],
transitionCompleted
completed
:
Bool
)
{
guard
let
vc
=
previousViewControllers
.
first
else
{
return
}
guard
let
index
=
viewControllers
.
index
(
of
:
vc
)
else
{
return
}
guard
completed
else
{
tabBar
.
select
(
at
:
index
)
{
[
weak
self
]
_
in
guard
let
s
=
self
else
{
return
}
s
.
animating
=
false
}
return
}
}
}
}
extension
PageController
:
UIPageViewControllerDataSource
{
extension
PageController
:
UIPageViewControllerDataSource
{
...
@@ -190,3 +218,28 @@ extension PageController: UIPageViewControllerDataSource {
...
@@ -190,3 +218,28 @@ extension PageController: UIPageViewControllerDataSource {
return
viewControllers
[
next
]
return
viewControllers
[
next
]
}
}
}
}
extension
PageController
:
UIScrollViewDelegate
{
public
func
scrollViewDidScroll
(
_
scrollView
:
UIScrollView
)
{
guard
!
animating
else
{
return
}
let
x
=
scrollView
.
contentOffset
.
x
/
scrollView
.
contentSize
.
width
*
scrollView
.
width
guard
0
<
x
else
{
return
}
tabBar
.
line
.
x
=
x
print
(
"scrolling"
,
x
)
}
public
func
scrollViewDidEndDecelerating
(
_
scrollView
:
UIScrollView
)
{
// animating = true
}
public
func
scrollViewWillBeginDecelerating
(
_
scrollView
:
UIScrollView
)
{
animating
=
true
}
}
Sources/iOS/TabBar.swift
View file @
6554f20e
...
@@ -185,6 +185,27 @@ open class TabBar: View {
...
@@ -185,6 +185,27 @@ open class TabBar: View {
/// Handles the button touch event.
/// Handles the button touch event.
@objc
@objc
internal
func
handleButton
(
button
:
UIButton
)
{
internal
func
handleButton
(
button
:
UIButton
)
{
animate
(
to
:
button
)
}
/**
Selects a given index from the buttons array.
- Parameter at index: An Int.
- Paramater completion: An optional completion block.
*/
open
func
select
(
at
index
:
Int
,
completion
:
(
@escaping
(
UIButton
)
->
Void
)?
=
nil
)
{
guard
-
1
<
index
,
index
<
buttons
.
count
else
{
return
}
animate
(
to
:
buttons
[
index
],
completion
:
completion
)
}
/**
Animates to a given button.
- Parameter to button: A UIButton.
- Paramater completion: An optional completion block.
*/
internal
func
animate
(
to
button
:
UIButton
,
completion
:
(
@escaping
(
UIButton
)
->
Void
)?
=
nil
)
{
delegate
?
.
tabBarWillSelectButton
?(
tabBar
:
self
,
button
:
button
)
delegate
?
.
tabBarWillSelectButton
?(
tabBar
:
self
,
button
:
button
)
selected
=
button
selected
=
button
...
@@ -194,11 +215,12 @@ open class TabBar: View {
...
@@ -194,11 +215,12 @@ open class TabBar: View {
}
}
s
.
line
.
x
=
button
.
x
s
.
line
.
x
=
button
.
x
s
.
line
.
width
=
button
.
width
s
.
line
.
width
=
button
.
width
})
{
[
weak
self
,
button
=
button
]
_
in
})
{
[
weak
self
,
button
=
button
,
completion
=
completion
]
_
in
guard
let
s
=
self
else
{
guard
let
s
=
self
else
{
return
return
}
}
s
.
delegate
?
.
tabBarDidSelectButton
?(
tabBar
:
s
,
button
:
button
)
s
.
delegate
?
.
tabBarDidSelectButton
?(
tabBar
:
s
,
button
:
button
)
completion
?(
button
)
}
}
}
}
...
...
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