Target Value Animation | Animated Time Display |
---|---|
The FlipNumberView
is simulating an analog flip display (e.g. like those at the airport / train station). It's well abstracted and easy to use. The FlipImageView
let's you run a similar animation on any view, e.g. images. See the example project for working examples (You can run pod try JDFlipNumberView
to open the example project quickly.). Please open a Github issue, if you think anything is missing or wrong.
pod 'JDFlipNumberView'
all flip views, SwiftUI views & default imagesetTo further limit what you depend on, use the following subpods. They don't include the default image bundle, thus they are much more lightweight. See Customization below for infos, on how to use your own images.
pod 'JDFlipNumberView/NoImageBundle'
, everything except the default image bundlepod 'JDFlipNumberView/NoImageBundle-NoSwiftUI'
, everything except the default image bundle & the SwiftUI viewsEven more targeted:
pod 'JDFlipNumberView/Core'
, only the JDFlipNumberView
pod 'JDFlipNumberView/FlipImageView'
, only the JDFlipImageView
pod 'JDFlipNumberView/FlipClockView'
, /Core
+ JDFlipClockView
pod 'JDFlipNumberView/DateCountdownFlipView'
, /Core
+ JDDateCountdownFlipView
pod 'JDFlipNumberView/DefaultImageBundle'
, the default image bundle, as it's not included automatically in the other subpods(For infos on cocoapods, have a look the cocoapods website)
JDFlipNumberView/JDFlipNumberView/*.{h,m}
to your projectJDFlipNumberView.bundle
, if you want to use the default imagesThe main classes are
JDFlipNumberView
(SwiftUI: FlipNumberView
)
JDFlipImageView
(SwiftUI: FlipImageView
)
setImageAnimated:duration:completion:
JDDateCountdownFlipView
(SwiftUI: DateCountdownFlipView
)
JDFlipClockView
(SwiftUI: FlipClockView
)
UIView+JDFlipImageView
After installing you only need to follow some simple steps to get started. Here is a working example: A 4-digit FlipNumberView
animating down once every second.
Objective-C + UIKit:
// create a new FlipNumberView, set a value, start an animation
JDFlipNumberView *flipNumberView = [[JDFlipNumberView alloc] initWithInitialValue: 1337];
[flipNumberView animateDownWithTimeInterval: 1.0];
// add to view hierarchy and resize
[self.view addSubview: flipNumberView];
[flipNumberView sizeToFit];
flipNumberView.center = self.view.center;
In SwiftUI it's even simpler:
struct SwiftExample: View {
@State var value = 1337
var body: some View {
FlipNumberView(value: $value, animationStyle: .interval(interval: 1.0, direction: .down))
.frame(height: 80)
}
}
That's it. This will display a working, flipping, animating countdown view!
See the example project for other examples.
- (void)setValue:(NSInteger)newValue animated:(BOOL)animated;
- (void)animateToNextNumber;
- (void)animateToPreviousNumber;
- (void)animateToValue:(NSInteger)newValue duration:(CGFloat)duration;
timeInterval
):- (void)animateUpWithTimeInterval:(NSTimeInterval)timeInterval;
- (void)animateDownWithTimeInterval:(NSTimeInterval)timeInterval;
In SwiftUI, see these:
public enum FlipNumberViewAnimationStyle {
case none
case simple
case continuous(duration: Double)
case interval(interval: Double, direction: FlipNumberViewIntervalAnimationDirection)
}
A) Replace original images
Replace the images within the JDFlipNumberView.bundle
. (In the Finder just Rightclick > Show Contents
to see the images.)
When using Pods, make sure to use
pod 'JDFlipNumberView/Core'
, so the default bundle won't be copied. Just create a bundle namedJDFlipNumberView.bundle
in your project yourself.
B) Use multiple bundles
Add another graphics bundle to your project. A bundle is nothing else, than a regular folder, but named with .bundle
as extension. You need one image per digit. 0.png, 1.png, 2.png, etc.
See the next section on how to use multiple bundles.
To use your own bundles, use the imageBundle:
initializers:
[[JDFlipNumberView alloc] initWithDigitCount:<#count#>
imageBundle:[JDFlipNumberViewImageBundle imageBundleNamed:@"<#imageBundleName#>"]];
[[JDDateCountdownFlipView alloc] initWithDayDigitCount:<#count#>
imageBundle:[JDFlipNumberViewImageBundle imageBundleNamed:@"<#imageBundleName#>"]];
SwiftUI:
FlipNumberView(value: <#valueBinding#>, imageBundle: JDFlipNumberViewImageBundle(named: "<#imageBundleName#>"))
Feel free to use the original .psd
file from the gfx
folder to create custom numbers.
I'm @calimarkus on Twitter. Maybe tweet, if you like JDFlipNumberView
!
I found "FlipClock-SwiftUI" by @elpassion - a fully native SwiftUI flip-clock. It could be a good starting point for a native swift rewrite. I'm playing around with it in a fork a bit: FlipNumberView-Swift.