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
09446a7f
Commit
09446a7f
authored
Oct 05, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding ImageCardView
parent
63296568
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
661 additions
and
52 deletions
+661
-52
MaterialKit.xcodeproj/project.pbxproj
+4
-0
Source/ImageCardView.swift
+421
-0
Source/MaterialBasicAnimation.swift
+108
-3
Source/MaterialButton.swift
+44
-25
Source/MaterialPulseView.swift
+42
-24
Source/MaterialTheme.swift
+42
-0
No files found.
MaterialKit.xcodeproj/project.pbxproj
View file @
09446a7f
...
...
@@ -58,6 +58,7 @@
964B17D51BBB31C2002A9CA0
/* MaterialAnimation.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
65BDD1731BB8D443006F7F2B
/* MaterialAnimation.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
964B17D61BBB31C2002A9CA0
/* MaterialLayout.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
964B17B31BBA447F002A9CA0
/* MaterialLayout.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
964B17D91BBB3911002A9CA0
/* BasicCardView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
964B17D81BBB3911002A9CA0
/* BasicCardView.swift */
;
settings
=
{
ASSET_TAGS
=
();
};
};
96D26BFD1BC23649006478BD
/* ImageCardView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96D26BFC1BC23649006478BD
/* ImageCardView.swift */
;
settings
=
{
ASSET_TAGS
=
();
};
};
9A94D0FA1B895EA500F586A5
/* LICENSE in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
963832631B88E5BF0015F710
/* LICENSE */
;
};
9A94D0FB1B895EA500F586A5
/* Roboto-Regular.ttf in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9AAC38591B8956E300FE6B2D
/* Roboto-Regular.ttf */
;
};
9A94D0FC1B895EA500F586A5
/* Roboto-Medium.ttf in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9AAC38571B8956CF00FE6B2D
/* Roboto-Medium.ttf */
;
};
...
...
@@ -108,6 +109,7 @@
964B17B31BBA447F002A9CA0
/* MaterialLayout.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialLayout.swift
;
sourceTree
=
"<group>"
;
};
964B17B51BBA4BEA002A9CA0
/* MaterialStatusBarStyle.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialStatusBarStyle.swift
;
sourceTree
=
"<group>"
;
};
964B17D81BBB3911002A9CA0
/* BasicCardView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
BasicCardView.swift
;
sourceTree
=
"<group>"
;
};
96D26BFC1BC23649006478BD
/* ImageCardView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ImageCardView.swift
;
sourceTree
=
"<group>"
;
};
9AAC38551B8956C500FE6B2D
/* Roboto-Light.ttf */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
"Roboto-Light.ttf"
;
sourceTree
=
"<group>"
;
};
9AAC38571B8956CF00FE6B2D
/* Roboto-Medium.ttf */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
"Roboto-Medium.ttf"
;
sourceTree
=
"<group>"
;
};
9AAC38591B8956E300FE6B2D
/* Roboto-Regular.ttf */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
"Roboto-Regular.ttf"
;
sourceTree
=
"<group>"
;
};
...
...
@@ -273,6 +275,7 @@
isa
=
PBXGroup
;
children
=
(
964B17D81BBB3911002A9CA0
/* BasicCardView.swift */
,
96D26BFC1BC23649006478BD
/* ImageCardView.swift */
,
);
name
=
Card
;
sourceTree
=
"<group>"
;
...
...
@@ -444,6 +447,7 @@
65AD15EA1BC05B3A0068AF9C
/* MaterialLayer.swift in Sources */
,
65BDD1521BB6EE7C006F7F2B
/* RobotoFont.swift in Sources */
,
964B17D91BBB3911002A9CA0
/* BasicCardView.swift in Sources */
,
96D26BFD1BC23649006478BD
/* ImageCardView.swift in Sources */
,
65BDD1591BB6FE3E006F7F2B
/* FlatButton.swift in Sources */
,
65BDD1791BB99C0F006F7F2B
/* RaisedButton.swift in Sources */
,
964B17B41BBA447F002A9CA0
/* MaterialLayout.swift in Sources */
,
...
...
Source/ImageCardView.swift
0 → 100644
View file @
09446a7f
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import
UIKit
public
class
ImageCardView
:
MaterialPulseView
{
//
// :name: dividerLayer
//
internal
var
dividerLayer
:
CAShapeLayer
?
//
// :name: dividerColor
//
public
var
dividerColor
:
UIColor
?
{
didSet
{
dividerLayer
?
.
backgroundColor
=
dividerColor
?
.
CGColor
reloadView
()
}
}
/**
:name: divider
*/
public
var
divider
:
Bool
=
MaterialTheme
.
imageCardView
.
divider
{
didSet
{
reloadView
()
}
}
/**
:name: contentInsets
*/
public
var
contentInsets
:
MaterialInsets
?
{
didSet
{
contentInsetsRef
=
nil
==
contentInsets
?
nil
:
MaterialInsetsToValue
(
contentInsets
!
)
}
}
/**
:name: contentInsetsRef
*/
public
var
contentInsetsRef
:
MaterialInsetsType
!
{
didSet
{
contentInsetsRef
=
nil
==
contentInsetsRef
?
(
top
:
0
,
left
:
0
,
bottom
:
0
,
right
:
0
)
:
contentInsetsRef
!
reloadView
()
}
}
/**
:name: titleLabelInsets
*/
public
var
titleLabelInsets
:
MaterialInsets
?
{
didSet
{
titleLabelInsetsRef
=
nil
==
titleLabelInsets
?
nil
:
MaterialInsetsToValue
(
titleLabelInsets
!
)
}
}
/**
:name: titleLabelInsetsRef
*/
public
var
titleLabelInsetsRef
:
MaterialInsetsType
!
{
didSet
{
titleLabelInsetsRef
=
nil
==
titleLabelInsetsRef
?
(
top
:
0
,
left
:
0
,
bottom
:
0
,
right
:
0
)
:
titleLabelInsetsRef
!
reloadView
()
}
}
/**
:name: titleLabel
*/
public
var
titleLabel
:
UILabel
?
{
didSet
{
titleLabel
?
.
translatesAutoresizingMaskIntoConstraints
=
false
reloadView
()
}
}
/**
:name: detailLabelInsets
*/
public
var
detailLabelInsets
:
MaterialInsets
?
{
didSet
{
detailLabelInsetsRef
=
nil
==
detailLabelInsets
?
nil
:
MaterialInsetsToValue
(
detailLabelInsets
!
)
}
}
/**
:name: detailLabelInsetsRef
*/
public
var
detailLabelInsetsRef
:
MaterialInsetsType
!
{
didSet
{
detailLabelInsetsRef
=
nil
==
detailLabelInsetsRef
?
(
top
:
0
,
left
:
0
,
bottom
:
0
,
right
:
0
)
:
detailLabelInsetsRef
!
reloadView
()
}
}
/**
:name: detailLabel
*/
public
var
detailLabel
:
UILabel
?
{
didSet
{
detailLabel
?
.
translatesAutoresizingMaskIntoConstraints
=
false
reloadView
()
}
}
/**
:name: leftButtonsInsets
*/
public
var
leftButtonsInsets
:
MaterialInsets
?
{
didSet
{
leftButtonsInsetsRef
=
nil
==
leftButtonsInsets
?
nil
:
MaterialInsetsToValue
(
leftButtonsInsets
!
)
}
}
/**
:name: leftButtonsInsetsRef
*/
public
var
leftButtonsInsetsRef
:
MaterialInsetsType
!
{
didSet
{
leftButtonsInsetsRef
=
nil
==
leftButtonsInsetsRef
?
(
top
:
0
,
left
:
0
,
bottom
:
0
,
right
:
0
)
:
leftButtonsInsetsRef
!
reloadView
()
}
}
/**
:name: leftButtons
*/
public
var
leftButtons
:
Array
<
UIButton
>
?
{
didSet
{
if
let
v
=
leftButtons
{
for
b
in
v
{
b
.
translatesAutoresizingMaskIntoConstraints
=
false
}
}
reloadView
()
}
}
/**
:name: rightButtonsInsets
*/
public
var
rightButtonsInsets
:
MaterialInsets
?
{
didSet
{
rightButtonsInsetsRef
=
nil
==
rightButtonsInsets
?
nil
:
MaterialInsetsToValue
(
rightButtonsInsets
!
)
}
}
/**
:name: rightButtonsInsetsRef
*/
public
var
rightButtonsInsetsRef
:
MaterialInsetsType
!
{
didSet
{
rightButtonsInsetsRef
=
nil
==
rightButtonsInsetsRef
?
(
top
:
0
,
left
:
0
,
bottom
:
0
,
right
:
0
)
:
rightButtonsInsetsRef
!
reloadView
()
}
}
/**
:name: rightButtons
*/
public
var
rightButtons
:
Array
<
UIButton
>
?
{
didSet
{
if
let
v
=
rightButtons
{
for
b
in
v
{
b
.
translatesAutoresizingMaskIntoConstraints
=
false
}
}
reloadView
()
}
}
/**
:name: init
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
}
/**
:name: init
*/
public
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
}
/**
:name: init
*/
public
convenience
init
()
{
self
.
init
(
frame
:
CGRectNull
)
}
/**
:name: init
*/
public
convenience
init
?(
titleLabel
:
UILabel
?
=
nil
,
detailLabel
:
UILabel
?
=
nil
,
leftButtons
:
Array
<
UIButton
>
?
=
nil
,
rightButtons
:
Array
<
UIButton
>
?
=
nil
)
{
self
.
init
(
frame
:
CGRectNull
)
prepareProperties
(
titleLabel
,
detailLabel
:
detailLabel
,
leftButtons
:
leftButtons
,
rightButtons
:
rightButtons
)
}
/**
:name: layoutSubviews
*/
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
// divider
if
true
==
divider
{
var
y
:
CGFloat
=
0
if
0
<
leftButtons
?
.
count
{
y
+=
contentInsetsRef
!.
bottom
+
leftButtonsInsetsRef
!.
top
+
leftButtonsInsetsRef
!.
bottom
+
leftButtons
!
[
0
]
.
frame
.
size
.
height
}
else
if
0
<
rightButtons
?
.
count
{
y
+=
contentInsetsRef
!.
bottom
+
rightButtonsInsetsRef
!.
top
+
rightButtonsInsetsRef
!.
bottom
+
rightButtons
!
[
0
]
.
frame
.
size
.
height
}
if
0
<
y
{
prepareDivider
(
bounds
.
size
.
height
-
y
-
0.5
,
width
:
bounds
.
size
.
width
)
}
}
else
{
dividerLayer
?
.
removeFromSuperlayer
()
dividerLayer
=
nil
}
}
/**
:name: reloadView
*/
public
func
reloadView
()
{
// clear constraints so new ones do not conflict
removeConstraints
(
constraints
)
for
v
in
subviews
{
v
.
removeFromSuperview
()
}
var
verticalFormat
:
String
=
"V:|"
var
views
:
Dictionary
<
String
,
AnyObject
>
=
Dictionary
<
String
,
AnyObject
>
()
var
metrics
:
Dictionary
<
String
,
AnyObject
>
=
Dictionary
<
String
,
AnyObject
>
()
if
nil
!=
titleLabel
{
verticalFormat
+=
"-(insetTop)"
metrics
[
"insetTop"
]
=
contentInsetsRef
!.
top
+
titleLabelInsetsRef
!.
top
}
else
if
nil
!=
detailLabel
{
verticalFormat
+=
"-(insetTop)"
metrics
[
"insetTop"
]
=
contentInsetsRef
!.
top
+
detailLabelInsetsRef
!.
top
}
// title
if
let
v
=
titleLabel
{
verticalFormat
+=
"-[titleLabel]"
views
[
"titleLabel"
]
=
v
addSubview
(
v
)
MaterialLayout
.
alignToParentHorizontallyWithInsets
(
self
,
child
:
v
,
left
:
contentInsetsRef
!.
left
+
titleLabelInsetsRef
!.
left
,
right
:
contentInsetsRef
!.
right
+
titleLabelInsetsRef
!.
right
)
}
// detail
if
let
v
=
detailLabel
{
if
nil
!=
titleLabel
{
verticalFormat
+=
"-(insetB)"
metrics
[
"insetB"
]
=
titleLabelInsetsRef
!.
bottom
+
detailLabelInsetsRef
!.
top
}
verticalFormat
+=
"-[detailLabel]"
views
[
"detailLabel"
]
=
v
addSubview
(
v
)
MaterialLayout
.
alignToParentHorizontallyWithInsets
(
self
,
child
:
v
,
left
:
contentInsetsRef
!.
left
+
detailLabelInsetsRef
!.
left
,
right
:
contentInsetsRef
!.
right
+
detailLabelInsetsRef
!.
right
)
}
// leftButtons
if
let
v
=
leftButtons
{
if
0
<
v
.
count
{
var
h
:
String
=
"H:|"
var
d
:
Dictionary
<
String
,
AnyObject
>
=
Dictionary
<
String
,
AnyObject
>
()
var
i
:
Int
=
0
for
b
in
v
{
let
k
:
String
=
"b
\(
i
)
"
d
[
k
]
=
b
if
0
==
i
++
{
h
+=
"-(left)-"
}
else
{
h
+=
"-(left_right)-"
}
h
+=
"[
\(
k
)
]"
addSubview
(
b
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInsetsRef
!.
bottom
+
leftButtonsInsetsRef
!.
bottom
)
}
addConstraints
(
MaterialLayout
.
constraint
(
h
,
options
:
[],
metrics
:
[
"left"
:
leftButtonsInsetsRef
!.
left
,
"left_right"
:
leftButtonsInsetsRef
!.
left
+
leftButtonsInsetsRef
!.
right
],
views
:
d
))
}
}
// rightButtons
if
let
v
=
rightButtons
{
if
0
<
v
.
count
{
var
h
:
String
=
"H:"
var
d
:
Dictionary
<
String
,
AnyObject
>
=
Dictionary
<
String
,
AnyObject
>
()
var
i
:
Int
=
0
for
b
in
v
{
let
k
:
String
=
"b
\(
i
)
"
d
[
k
]
=
b
h
+=
"[
\(
k
)
]"
if
0
==
i
++
{
h
+=
"-(right_left)-"
}
else
{
h
+=
"-(right)-"
}
addSubview
(
b
)
MaterialLayout
.
alignFromBottom
(
self
,
child
:
b
,
bottom
:
contentInsetsRef
!.
bottom
+
rightButtonsInsetsRef
!.
bottom
)
}
addConstraints
(
MaterialLayout
.
constraint
(
h
+
"|"
,
options
:
[],
metrics
:
[
"right"
:
rightButtonsInsetsRef
!.
right
,
"right_left"
:
rightButtonsInsetsRef
!.
right
+
rightButtonsInsetsRef
!.
left
],
views
:
d
))
}
}
if
0
<
leftButtons
?
.
count
{
verticalFormat
+=
"-(insetC)-[button]"
views
[
"button"
]
=
leftButtons
!
[
0
]
metrics
[
"insetC"
]
=
leftButtonsInsetsRef
!.
top
metrics
[
"insetBottom"
]
=
contentInsetsRef
!.
bottom
+
leftButtonsInsetsRef
!.
bottom
}
else
if
0
<
rightButtons
?
.
count
{
verticalFormat
+=
"-(insetC)-[button]"
views
[
"button"
]
=
rightButtons
!
[
0
]
metrics
[
"insetC"
]
=
rightButtonsInsetsRef
!.
top
metrics
[
"insetBottom"
]
=
contentInsetsRef
!.
bottom
+
rightButtonsInsetsRef
!.
bottom
}
if
nil
!=
detailLabel
{
if
nil
==
metrics
[
"insetC"
]
{
metrics
[
"insetBottom"
]
=
contentInsetsRef
!.
bottom
+
detailLabelInsetsRef
!.
bottom
}
else
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
detailLabelInsetsRef
!.
bottom
}
}
else
if
nil
!=
titleLabel
{
if
nil
==
metrics
[
"insetC"
]
{
metrics
[
"insetBottom"
]
=
contentInsetsRef
!.
bottom
+
titleLabelInsetsRef
!.
bottom
}
else
{
metrics
[
"insetC"
]
=
(
metrics
[
"insetC"
]
as!
CGFloat
)
+
titleLabelInsetsRef
!.
bottom
}
}
if
0
<
views
.
count
{
verticalFormat
+=
"-(insetBottom)-|"
addConstraints
(
MaterialLayout
.
constraint
(
verticalFormat
,
options
:
[],
metrics
:
metrics
,
views
:
views
))
}
}
//
// :name: prepareDivider
//
internal
func
prepareDivider
(
y
:
CGFloat
,
width
:
CGFloat
)
{
if
nil
==
dividerLayer
{
dividerLayer
=
CAShapeLayer
()
dividerLayer
!.
backgroundColor
=
dividerColor
?
.
CGColor
dividerLayer
!.
frame
=
CGRectMake
(
0
,
y
,
width
,
1
)
dividerLayer
!.
zPosition
=
0
layer
.
addSublayer
(
dividerLayer
!
)
}
}
//
// :name: prepareProperties
//
internal
func
prepareProperties
(
titleLabel
:
UILabel
?,
detailLabel
:
UILabel
?,
leftButtons
:
Array
<
UIButton
>
?,
rightButtons
:
Array
<
UIButton
>
?)
{
self
.
titleLabel
=
titleLabel
self
.
detailLabel
=
detailLabel
self
.
leftButtons
=
leftButtons
self
.
rightButtons
=
rightButtons
}
//
// :name: prepareView
//
internal
override
func
prepareView
()
{
super
.
prepareView
()
userInteractionEnabled
=
MaterialTheme
.
imageCardView
.
userInteractionEnabled
backgroundColor
=
MaterialTheme
.
imageCardView
.
backgroundColor
contentInsetsRef
=
MaterialTheme
.
imageCardView
.
contentInsetsRef
titleLabelInsetsRef
=
MaterialTheme
.
imageCardView
.
titleLabelInsetsRef
detailLabelInsetsRef
=
MaterialTheme
.
imageCardView
.
detailLabelInsetsRef
leftButtonsInsetsRef
=
MaterialTheme
.
imageCardView
.
leftButtonsInsetsRef
rightButtonsInsetsRef
=
MaterialTheme
.
imageCardView
.
rightButtonsInsetsRef
contentsRect
=
MaterialTheme
.
imageCardView
.
contentsRect
contentsCenter
=
MaterialTheme
.
imageCardView
.
contentsCenter
contentsScale
=
MaterialTheme
.
imageCardView
.
contentsScale
contentsGravity
=
MaterialTheme
.
imageCardView
.
contentsGravity
shadowDepth
=
MaterialTheme
.
imageCardView
.
shadowDepth
shadowColor
=
MaterialTheme
.
imageCardView
.
shadowColor
zPosition
=
MaterialTheme
.
imageCardView
.
zPosition
masksToBounds
=
MaterialTheme
.
imageCardView
.
masksToBounds
cornerRadius
=
MaterialTheme
.
imageCardView
.
cornerRadius
borderWidth
=
MaterialTheme
.
imageCardView
.
borderWidth
borderColor
=
MaterialTheme
.
imageCardView
.
bordercolor
dividerColor
=
MaterialTheme
.
imageCardView
.
dividerColor
}
}
Source/MaterialBasicAnimation.swift
View file @
09446a7f
...
...
@@ -67,10 +67,115 @@ public extension MaterialAnimation {
/**
:name: scale
*/
public
static
func
scale
(
transform
:
CATransform3D
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
scale
(
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform"
animation
.
toValue
=
NSValue
(
CATransform3D
:
transform
)
animation
.
keyPath
=
"transform.scale"
animation
.
toValue
=
scale
as
NSNumber
animation
.
fillMode
=
MaterialAnimationFillModeToValue
(
.
Forwards
)
animation
.
removedOnCompletion
=
false
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
/**
:name: scaleX
*/
public
static
func
scaleX
(
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform.scale.x"
animation
.
toValue
=
scale
as
NSNumber
animation
.
fillMode
=
MaterialAnimationFillModeToValue
(
.
Forwards
)
animation
.
removedOnCompletion
=
false
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
/**
:name: scaleY
*/
public
static
func
scaleY
(
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform.scale.y"
animation
.
toValue
=
scale
as
NSNumber
animation
.
fillMode
=
MaterialAnimationFillModeToValue
(
.
Forwards
)
animation
.
removedOnCompletion
=
false
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
/**
:name: scaleZ
*/
public
static
func
scaleZ
(
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform.scale.z"
animation
.
toValue
=
scale
as
NSNumber
animation
.
fillMode
=
MaterialAnimationFillModeToValue
(
.
Forwards
)
animation
.
removedOnCompletion
=
false
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
/**
:name: translation
*/
public
static
func
translation
(
translation
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform.translation"
animation
.
toValue
=
translation
as
NSNumber
animation
.
fillMode
=
MaterialAnimationFillModeToValue
(
.
Forwards
)
animation
.
removedOnCompletion
=
false
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
/**
:name: translationX
*/
public
static
func
translationX
(
translation
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform.translation.x"
animation
.
toValue
=
translation
as
NSNumber
animation
.
fillMode
=
MaterialAnimationFillModeToValue
(
.
Forwards
)
animation
.
removedOnCompletion
=
false
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
/**
:name: translationY
*/
public
static
func
translationY
(
translation
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform.translation.y"
animation
.
toValue
=
translation
as
NSNumber
animation
.
fillMode
=
MaterialAnimationFillModeToValue
(
.
Forwards
)
animation
.
removedOnCompletion
=
false
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
/**
:name: translationZ
*/
public
static
func
translationZ
(
translation
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform.translation.z"
animation
.
toValue
=
translation
as
NSNumber
animation
.
fillMode
=
MaterialAnimationFillModeToValue
(
.
Forwards
)
animation
.
removedOnCompletion
=
false
if
let
d
=
duration
{
...
...
Source/MaterialButton.swift
View file @
09446a7f
...
...
@@ -20,11 +20,6 @@ import UIKit
public
class
MaterialButton
:
UIButton
{
/**
:name: spotlight
*/
public
lazy
var
spotlight
:
Bool
=
false
/**
:name: visualLayer
*/
public
private(set)
lazy
var
visualLayer
:
CAShapeLayer
=
CAShapeLayer
()
...
...
@@ -40,9 +35,26 @@ public class MaterialButton : UIButton {
public
lazy
var
pulseScale
:
Bool
=
true
/**
:name: spotlight
*/
public
var
spotlight
:
Bool
=
false
{
didSet
{
if
spotlight
{
pulseFill
=
false
}
}
}
/**
:name: pulseFill
*/
public
lazy
var
pulseFill
:
Bool
=
false
public
var
pulseFill
:
Bool
=
false
{
didSet
{
if
pulseFill
{
spotlight
=
false
}
}
}
/**
:name: pulseColorOpacity
...
...
@@ -385,26 +397,25 @@ public class MaterialButton : UIButton {
let
point
:
CGPoint
=
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
)
if
true
==
layer
.
containsPoint
(
point
)
{
let
s
:
CGFloat
=
(
width
<
height
?
height
:
width
)
/
2
let
f
:
CGFloat
=
3
let
f
:
CGFloat
=
4
let
v
:
CGFloat
=
s
/
f
let
d
:
CGFloat
=
pulseFill
?
5
*
f
:
2
*
f
let
d
:
CGFloat
=
2
*
f
let
r
:
CGFloat
=
1.05
let
a
:
CFTimeInterval
=
0.25
let
t
:
CFTimeInterval
=
0.25
MaterialAnimation
.
animationDisabled
({
self
.
pulseLayer
.
hidden
=
false
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
v
,
v
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
s
/
d
})
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
MaterialAnimation
.
animationDisabled
({
self
.
pulseLayer
.
hidden
=
false
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
v
,
v
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
s
/
d
})
pulseLayer
.
addAnimation
(
MaterialAnimation
.
scale
(
pulseFill
?
3
*
d
:
1.5
*
d
,
duration
:
t
),
forKey
:
nil
)
}
if
pulseScale
{
layer
.
addAnimation
(
MaterialAnimation
.
scale
(
CATransform3DMakeScale
(
r
,
r
,
r
),
duration
:
a
),
forKey
:
nil
)
layer
.
addAnimation
(
MaterialAnimation
.
scale
(
r
,
duration
:
t
),
forKey
:
nil
)
}
MaterialAnimation
.
animationWithDuration
(
a
,
animations
:
{
self
.
pulseLayer
.
transform
=
CATransform3DMakeScale
(
d
,
d
,
d
)
})
}
}
...
...
@@ -480,10 +491,17 @@ public class MaterialButton : UIButton {
// :name: shrink
//
internal
func
shrink
()
{
MaterialAnimation
.
animationWithDuration
(
0.25
,
animations
:
{
self
.
pulseLayer
.
hidden
=
true
self
.
pulseLayer
.
transform
=
CATransform3DIdentity
})
self
.
layer
.
addAnimation
(
MaterialAnimation
.
scale
(
CATransform3DIdentity
),
forKey
:
nil
)
let
t
:
CFTimeInterval
=
0.25
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
MaterialAnimation
.
animationWithDuration
(
t
,
animations
:
{
self
.
pulseLayer
.
hidden
=
true
})
pulseLayer
.
addAnimation
(
MaterialAnimation
.
scale
(
1
,
duration
:
t
),
forKey
:
nil
)
}
if
pulseScale
{
layer
.
addAnimation
(
MaterialAnimation
.
scale
(
1
,
duration
:
t
),
forKey
:
nil
)
}
}
}
\ No newline at end of file
Source/MaterialPulseView.swift
View file @
09446a7f
...
...
@@ -20,11 +20,6 @@ import UIKit
public
class
MaterialPulseView
:
MaterialView
{
/**
:name: spotlight
*/
public
lazy
var
spotlight
:
Bool
=
false
/**
:name: pulseLayer
*/
public
private(set)
lazy
var
pulseLayer
:
CAShapeLayer
=
CAShapeLayer
()
...
...
@@ -35,9 +30,26 @@ public class MaterialPulseView : MaterialView {
public
lazy
var
pulseScale
:
Bool
=
true
/**
:name: spotlight
*/
public
var
spotlight
:
Bool
=
false
{
didSet
{
if
spotlight
{
pulseFill
=
false
}
}
}
/**
:name: pulseFill
*/
public
lazy
var
pulseFill
:
Bool
=
false
public
var
pulseFill
:
Bool
=
false
{
didSet
{
if
pulseFill
{
spotlight
=
false
}
}
}
/**
:name: pulseColorOpacity
...
...
@@ -67,24 +79,23 @@ public class MaterialPulseView : MaterialView {
let
s
:
CGFloat
=
(
width
<
height
?
height
:
width
)
/
2
let
f
:
CGFloat
=
3
let
v
:
CGFloat
=
s
/
f
let
d
:
CGFloat
=
pulseFill
?
5
*
f
:
2
*
f
let
d
:
CGFloat
=
2
*
f
let
r
:
CGFloat
=
1.05
let
a
:
CFTimeInterval
=
0.25
let
t
:
CFTimeInterval
=
0.25
MaterialAnimation
.
animationDisabled
({
self
.
pulseLayer
.
hidden
=
false
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
v
,
v
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
s
/
d
})
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
MaterialAnimation
.
animationDisabled
({
self
.
pulseLayer
.
hidden
=
false
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
v
,
v
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
s
/
d
})
pulseLayer
.
addAnimation
(
MaterialAnimation
.
scale
(
pulseFill
?
3
*
d
:
d
,
duration
:
t
),
forKey
:
nil
)
}
if
pulseScale
{
layer
.
addAnimation
(
MaterialAnimation
.
scale
(
CATransform3DMakeScale
(
r
,
r
,
r
),
duration
:
a
),
forKey
:
nil
)
layer
.
addAnimation
(
MaterialAnimation
.
scale
(
r
,
duration
:
t
),
forKey
:
nil
)
}
MaterialAnimation
.
animationWithDuration
(
a
,
animations
:
{
self
.
pulseLayer
.
transform
=
CATransform3DMakeScale
(
d
,
d
,
d
)
})
}
}
...
...
@@ -164,10 +175,17 @@ public class MaterialPulseView : MaterialView {
// :name: shrink
//
internal
func
shrink
()
{
MaterialAnimation
.
animationWithDuration
(
0.25
,
animations
:
{
self
.
pulseLayer
.
hidden
=
true
self
.
pulseLayer
.
transform
=
CATransform3DIdentity
})
self
.
layer
.
addAnimation
(
MaterialAnimation
.
scale
(
CATransform3DIdentity
),
forKey
:
nil
)
let
t
:
NSTimeInterval
=
0.25
if
nil
!=
pulseColor
&&
0
<
pulseColorOpacity
{
MaterialAnimation
.
animationWithDuration
(
t
,
animations
:
{
self
.
pulseLayer
.
hidden
=
true
})
pulseLayer
.
addAnimation
(
MaterialAnimation
.
scale
(
1
,
duration
:
t
),
forKey
:
nil
)
}
if
pulseScale
{
layer
.
addAnimation
(
MaterialAnimation
.
scale
(
1
,
duration
:
t
),
forKey
:
nil
)
}
}
}
Source/MaterialTheme.swift
View file @
09446a7f
...
...
@@ -22,6 +22,7 @@ public struct MaterialTheme {
public
struct
view
{}
public
struct
pulseView
{}
public
struct
basicCardView
{}
public
struct
imageCardView
{}
public
struct
navigationBarView
{}
public
struct
label
{}
public
struct
flatButton
{}
...
...
@@ -132,6 +133,47 @@ public extension MaterialTheme.basicCardView {
public
static
var
dividerColor
:
UIColor
=
MaterialColor
.
blueGrey
.
lighten5
}
// imageCardView
public
extension
MaterialTheme
.
imageCardView
{
// shadow
public
static
var
shadowDepth
:
MaterialDepth
=
.
Depth2
public
static
var
shadowColor
:
UIColor
=
MaterialColor
.
black
// shape
public
static
var
masksToBounds
:
Bool
=
true
public
static
var
cornerRadius
:
MaterialRadius
=
.
None
public
static
var
contentInsetsRef
:
MaterialInsetsType
=
MaterialInsetsToValue
(
.
Square3
)
public
static
var
titleLabelInsetsRef
:
MaterialInsetsType
=
MaterialInsetsToValue
(
.
Square2
)
public
static
var
detailLabelInsetsRef
:
MaterialInsetsType
=
(
top
:
0
,
left
:
8
,
bottom
:
16
,
right
:
8
)
public
static
var
leftButtonsInsetsRef
:
MaterialInsetsType
=
(
top
:
8
,
left
:
8
,
bottom
:
-
8
,
right
:
0
)
public
static
var
rightButtonsInsetsRef
:
MaterialInsetsType
=
(
top
:
8
,
left
:
0
,
bottom
:
-
8
,
right
:
8
)
// border
public
static
var
borderWidth
:
MaterialBorder
=
.
None
public
static
var
bordercolor
:
UIColor
=
MaterialColor
.
black
// color
public
static
var
backgroundColor
:
UIColor
=
MaterialColor
.
white
public
static
var
pulseColor
:
UIColor
=
MaterialColor
.
white
public
static
var
pulseColorOpacity
:
CGFloat
=
0.25
// interaction
public
static
var
userInteractionEnabled
:
Bool
=
true
// image
public
static
var
contentsRect
:
CGRect
=
CGRectMake
(
0
,
0
,
1
,
1
)
public
static
var
contentsCenter
:
CGRect
=
CGRectMake
(
0
,
0
,
1
,
1
)
public
static
var
contentsScale
:
CGFloat
=
UIScreen
.
mainScreen
()
.
scale
public
static
var
contentsGravity
:
MaterialGravity
=
.
ResizeAspectFill
// position
public
static
var
zPosition
:
CGFloat
=
0
// divider
public
static
var
divider
:
Bool
=
true
public
static
var
dividerColor
:
UIColor
=
MaterialColor
.
blueGrey
.
lighten5
}
// navigationBarView
public
extension
MaterialTheme
.
navigationBarView
{
// frame
...
...
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