This project serves two purposes:
-
It's a button I might use in another open source project (a customizable media player) but you can use it in your projects as well, if you just want the animated button and not the entire player.
-
I wanted to create an animation + secondary animation that is reversible through user interaction. WHAT? Okay, so the whole state transition is one keyframe animation, but I cannot just "reverse" the animation, because the secondary animation (animation caused by the movement of the right pause layer) behaves differently depending on the direction (this influences the bending of the line). Since the solution I came up with is not that perfect, which partly results from wrong timing functions, the reversble animation is under the
develop
branch and you can just check it out. I consider switching from theCADisplayLink
approach to a custom layer property animation, whereprogress
would range from0.0
to1.0
and when there is still an animation going on while hitting the button I would remove the animation and add the reverse animation with1.0 - progress
. That way I could avoid all the state tracking.
If you want to see how the reversible animation works, take a look at the develop
branch, or - if you just want to use it - paste this:
pod 'PlayButton', :git => 'https://github.com/fruitcoder/PlayButton.git', :commit => '7b287f7'
import PlayButton
let playButton = PlayButton(origin: CGPoint(x: 100, y: 100), width: 30.0, initialAction: .Pause)
playButton.addTarget(self, action: #selector(tap), forControlEvents: .TouchUpInside)
view.addSubview(playButton)
Or just add a UIButton
to your Storyboard and set the class to PlayButton
To run the example project, clone the repo, and run pod install
from the Example directory first.
- ARC
- iOS8
PlayButton is available through CocoaPods. To install it, simply add the following lines to your Podfile:
use_frameworks!
target '<Your Target Name>' do
pod 'PlayButton'
end
Then, run the following command:
$ pod install
Alexander Türk, [email protected]
PlayButton is available under the MIT license. See the LICENSE file for more info.