Skip to content

Fun with playgrounds and Core Animation. Android-inspired, material loading indicator.

License

Notifications You must be signed in to change notification settings

nsakaimbo/material-loading-indicator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Material Loading Indicator

Some fun with Core Animation - making an Android-inspired, material loading indicator.

This little project is based on a neat tutorial by Matthew Cheok on implementing an Android-inspired, material-style loading indicator, with some minor parameterization and re-factoring.

Update: Funny story: this harmless little project led to a very brief moment of Twitter celebrity.

Soon after posting this playground, I tweeted about an initialization technique learned from persuing Erica Sadun's Github, which I used for my re-factoring of this project. Namely, you can initialize a Swift constant without having to use intermediate property declarations within the initializing closure. Instead, you can refer to the initialized property using positional references, like so:

   let strokeStartAnimation: CAAnimation = {
            
            $0.beginTime = tailDelay
            $0.fromValue = 0.0
            $0.toValue = 1.0
            $0.duration = tailDuration
            $0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
            
            return $0
            
        }(CABasicAnimation(keyPath: "strokeStart"))

It's a minor tweak, but makes the declaration a lot more elegant to read (and to write). Apparently, the iOS community thought so too - enough to get re-tweeted over 100 times! In fact, it caused enough of a stir in the iOS-Twitterverse that within a day, Natasha The Robot had written a whole blog post about it!

Happy that everyone had fun with this tidbit. Makes me wonder how many of these little gems are still yet to be discovered (or popularized) as a result of a deeper understanding of the Swift language and its compiler.

About

Fun with playgrounds and Core Animation. Android-inspired, material loading indicator.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages