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
1b8a923d
Commit
1b8a923d
authored
Sep 26, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'development' of
https://github.com/CosmicMind/Material
into development
parents
ef355c28
c2ca0b6a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
0 deletions
+83
-0
Sources/iOS/Base.swift
+83
-0
No files found.
Sources/iOS/Base.swift
0 → 100644
View file @
1b8a923d
//
// Base.swift
// Material
//
// Created by Orkhan Alikhanov on 8/29/17.
// Copyright © 2017 BiAtoms. All rights reserved.
//
import
UIKit
class
Base
:
UIControl
{
let
titleLabel
=
UILabel
()
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
prepare
()
}
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
prepare
()
}
let
iconLayer
=
CALayer
()
var
selectedColor
=
UIColor
(
red
:
0.25
,
green
:
0.32
,
blue
:
0.71
,
alpha
:
1.0
)
var
normalColor
=
UIColor
.
gray
func
prepare
()
{
layer
.
addSublayer
(
iconLayer
)
self
.
addTarget
(
self
,
action
:
#selector(
didTap
)
,
for
:
.
touchUpInside
)
beforeFirstAnimation
()
firstAnimation
()
beforeSecondAnimation
()
secondAnimation
()
}
@objc
func
didTap
()
{
self
.
isSelected
=
!
self
.
isSelected
self
.
animate
()
}
var
sideLength
:
CGFloat
{
return
frame
.
height
}
override
var
intrinsicContentSize
:
CGSize
{
return
CGSize
(
width
:
132
,
height
:
132
)
}
func
beforeFirstAnimation
()
{}
func
firstAnimation
()
{}
func
beforeSecondAnimation
()
{}
func
secondAnimation
()
{}
var
isAnimating
=
false
let
totalDuration
:
TimeInterval
=
0.5
let
delayFactor
:
TimeInterval
=
0.33
var
duration
:
TimeInterval
{
return
totalDuration
/
(
1.0
+
delayFactor
+
1.0
)
}
func
animate
()
{
beforeFirstAnimation
()
CATransaction
.
animate
(
withDuration
:
duration
,
timingFunction
:
.
easeInOut
,
animations
:
{
self
.
isAnimating
=
true
self
.
firstAnimation
()
})
{
CATransaction
.
performWithoutAnimation
{
self
.
beforeSecondAnimation
()
}
CATransaction
.
animate
(
withDuration
:
self
.
duration
,
delay
:
self
.
duration
*
self
.
delayFactor
,
timingFunction
:
.
easeInOut
,
animations
:
{
self
.
secondAnimation
()
},
completion
:
{
self
.
isAnimating
=
false
})
}
}
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
let
size
=
CGSize
(
width
:
sideLength
,
height
:
sideLength
)
self
.
iconLayer
.
frame
.
size
=
size
}
}
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