-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New activity indicator newtonCradle
and circlePendulum
#573
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cae8b46
New activity indicator `newtonCradle` and `circlePendulum`
phimage 331f141
Update CHANGELOG and DOC for `newtonCradle` and `circlePendulum`
phimage b94fdaa
Better heat beating for `hearBeat` activity indicator
phimage c6a8e7b
Allow to edit variable to apply colors on activity indicator `triforc…
e-marchand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
Sources/ActivityIndicators/Animations/ActivityIndicatorAnimationCirclePendulum.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// ActivityIndicatorAnimationCirclePendulum.swift | ||
// IBAnimatable | ||
// | ||
// Created by phimage on 29/06/2018. | ||
// Copyright © 2018 IBAnimatable. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import UIKit | ||
|
||
public class ActivityIndicatorAnimationCirclePendulum: ActivityIndicatorAnimating { | ||
|
||
// MARK: Properties | ||
|
||
fileprivate let duration: CFTimeInterval = 1 | ||
fileprivate let ratio: CGFloat = 7 | ||
fileprivate let ballCount: Int = 3 | ||
|
||
#if LG | ||
fileprivate let trueColor = true | ||
#else | ||
fileprivate let trueColor = false | ||
#endif | ||
fileprivate let colors: [UIColor] = [.red, .blue, .yellow] | ||
|
||
fileprivate var ballSize: CGFloat = 0 | ||
|
||
// MARK: ActivityIndicatorAnimating | ||
|
||
public func configureAnimation(in layer: CALayer, size: CGSize, color: UIColor) { | ||
ballSize = size.height / ratio | ||
var xPos = (size.width - (CGFloat(ballCount) * ballSize)) / 2 | ||
let yPos = size.height - ballSize / 2 | ||
|
||
for i in 0 ..< ballCount { | ||
let ball = ActivityIndicatorShape.circle.makeLayer(size: CGSize(width: ballSize, height: ballSize), color: trueColor ? colors[i]: color) | ||
ball.frame = CGRect(x: xPos, y: yPos, width: ballSize, height: ballSize) | ||
ball.add(makeAnimation(for: ball, in: layer, size: size, pos: i), forKey: "animation") | ||
layer.addSublayer(ball) | ||
xPos += ballSize | ||
} | ||
} | ||
} | ||
|
||
private extension ActivityIndicatorAnimationCirclePendulum { | ||
|
||
func makeAnimation(for ball: CALayer, in layer: CALayer, size: CGSize, pos: Int) -> CAAnimation { | ||
let angle = 2 * atan(ballSize / (size.height - ballSize / 2)) | ||
|
||
var animations: [CAKeyframeAnimation] = [] // only 3 balls, code not generic yet, how to compute angles? | ||
|
||
let rotateAnimation = CAKeyframeAnimation(keyPath: .position) | ||
var animPos = 0 | ||
rotateAnimation.path = UIBezierPath(arcCenter: CGPoint(x: size.width / 2, y: size.height / 2), | ||
radius: size.height / 2, | ||
startAngle: CGFloat.pi / 2 + angle, | ||
endAngle: 2 * CGFloat.pi + CGFloat.pi / 2 - angle, | ||
clockwise: true).cgPath | ||
rotateAnimation.duration = duration | ||
rotateAnimation.timingFunctionType = .easeInOut | ||
rotateAnimation.beginTime = duration * CFTimeInterval((pos + animPos) % ballCount) | ||
animations.append(rotateAnimation) | ||
|
||
let rotateAnimation2 = CAKeyframeAnimation(keyPath: .position) | ||
animPos += 1 | ||
rotateAnimation2.path = UIBezierPath(arcCenter: CGPoint(x: size.width / 2, y: size.height / 2), | ||
radius: size.height / 2, | ||
startAngle: 2 * CGFloat.pi + CGFloat.pi / 2 - angle, | ||
endAngle: 2 * CGFloat.pi + CGFloat.pi / 2, | ||
clockwise: true).cgPath | ||
rotateAnimation2.duration = duration | ||
rotateAnimation2.timingFunctionType = .easeOutExpo | ||
rotateAnimation2.beginTime = duration * CFTimeInterval((pos + animPos) % ballCount) | ||
animations.append(rotateAnimation2) | ||
|
||
let rotateAnimation3 = CAKeyframeAnimation(keyPath: .position) | ||
animPos += 1 | ||
rotateAnimation3.path = UIBezierPath(arcCenter: CGPoint(x: size.width / 2, y: size.height / 2), | ||
radius: size.height / 2, | ||
startAngle: 2 * CGFloat.pi + CGFloat.pi / 2, | ||
endAngle: 2 * CGFloat.pi + CGFloat.pi / 2 + angle, | ||
clockwise: true).cgPath | ||
rotateAnimation3.duration = duration | ||
rotateAnimation3.timingFunctionType = .easeOutExpo | ||
rotateAnimation3.beginTime = duration * CFTimeInterval((pos + animPos) % ballCount) | ||
animations.append(rotateAnimation3) | ||
|
||
let animation = CAAnimationGroup() | ||
animation.animations = animations | ||
animation.duration = duration * CFTimeInterval(ballCount) | ||
animation.repeatCount = .infinity | ||
animation.isRemovedOnCompletion = false | ||
return animation | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Sources/ActivityIndicators/Animations/ActivityIndicatorAnimationNewtonCradle.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// ActivityIndicatorAnimationNewtonCradle.swift | ||
// IBAnimatable | ||
// | ||
// Created by phimage on 29/06/2018. | ||
// Copyright © 2018 IBAnimatable. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
public class ActivityIndicatorAnimationNewtonCradle: ActivityIndicatorAnimating { | ||
|
||
// MARK: Properties | ||
|
||
fileprivate let duration: CFTimeInterval = 0.4 | ||
fileprivate let ratio: CGFloat = 7 | ||
fileprivate let ballCount: Int = 5 | ||
fileprivate let timingFunction: TimingFunctionType = .easeOutQuad | ||
|
||
fileprivate var ballSize: CGFloat = 0 | ||
|
||
// MARK: ActivityIndicatorAnimating | ||
|
||
public func configureAnimation(in layer: CALayer, size: CGSize, color: UIColor) { | ||
ballSize = size.height / ratio | ||
var xPos = (size.width - (CGFloat(ballCount) * ballSize)) / 2 | ||
let yPos = size.height - ballSize / 2 | ||
|
||
var balls: [CALayer] = [] | ||
for _ in 0 ..< ballCount { | ||
let ball = ActivityIndicatorShape.circle.makeLayer(size: CGSize(width: ballSize, height: ballSize), color: color) | ||
ball.frame = CGRect(x: xPos, y: yPos, width: ballSize, height: ballSize) | ||
balls.append(ball) | ||
xPos += ballSize | ||
} | ||
|
||
let firstBall = balls.removeFirst() | ||
firstBall.add(makeAnimation(for: firstBall, in: layer, size: size, reverse: true), forKey: "animation") | ||
layer.addSublayer(firstBall) | ||
|
||
let lastBall = balls.removeLast() | ||
lastBall.add(makeAnimation(for: lastBall, in: layer, size: size, reverse: false), forKey: "animation") | ||
layer.addSublayer(lastBall) | ||
|
||
for ball in balls { | ||
layer.addSublayer(ball) | ||
} | ||
} | ||
} | ||
|
||
private extension ActivityIndicatorAnimationNewtonCradle { | ||
|
||
func makeAnimation(for ball: CALayer, in layer: CALayer, size: CGSize, reverse: Bool) -> CAAnimation { | ||
let rotateAnimation = CAKeyframeAnimation(keyPath: .position) | ||
rotateAnimation.path = UIBezierPath(arcCenter: CGPoint(x: ball.frame.origin.x + ballSize / 2, y: size.height / 2), | ||
radius: size.height / 2, | ||
startAngle: CGFloat.pi / 2, | ||
endAngle: reverse ? CGFloat.pi: 0, | ||
clockwise: reverse).cgPath | ||
rotateAnimation.duration = duration | ||
rotateAnimation.autoreverses = true | ||
rotateAnimation.timingFunctionType = timingFunction | ||
|
||
if reverse { | ||
rotateAnimation.beginTime = duration * 2 | ||
} | ||
|
||
let animation = CAAnimationGroup() | ||
animation.animations = [rotateAnimation] | ||
animation.duration = duration * 4 | ||
animation.repeatCount = .infinity | ||
animation.isRemovedOnCompletion = false | ||
return animation | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What means
LG
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Life's Good
This activity indicator has been inspired from my new tv, to watch the world cup
This override the color defined and set 3 colors.
Maybe
LG
could be used accidentally, If I could keep my eastern eggs, a longer compilation flag could be usedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we have a property instead of a custom flag? Otherwise, the user needs to set the configuration in Podfile to enable it like
build_settings['OTHER_SWIFT_FLAGS'] = '-LG'
. If you think that's fun, shall we add it to ActivityIndicators.md . BTW: I haveLG
big TV at home too 📺There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ActivityIndicatorAnimation classes are not very accessible, but I could make
trueColor
as apublic var
The compilation will change only the default value.
Yes I will add in doc
ps: same trick on triforce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phimage cool, thanks, LG(Life's Good), you make it even LB (Life's Better)😉