parent
0e48455fe3
commit
86a43066f4
|
@ -8,17 +8,17 @@ class ViewController: UIViewController {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
imageView.setAnimatableImage(named: "mugen.gif")
|
||||
imageView.startAnimating()
|
||||
imageView.startAnimatingGIF()
|
||||
UIApplication.sharedApplication().setStatusBarStyle(.LightContent, animated: false)
|
||||
}
|
||||
|
||||
@IBAction func toggleAnimation(button: UIButton) {
|
||||
if imageView.isAnimating {
|
||||
imageView.stopAnimating()
|
||||
if imageView.isAnimatingGIF {
|
||||
imageView.stopAnimatingGIF()
|
||||
button.layer.backgroundColor = UIColor.whiteColor().CGColor
|
||||
button.setTitleColor(UIColor.blackColor(), forState: .Normal)
|
||||
} else {
|
||||
imageView.startAnimating()
|
||||
imageView.startAnimatingGIF()
|
||||
button.layer.backgroundColor = UIColor.clearColor().CGColor
|
||||
button.setTitleColor(UIColor.whiteColor(), forState: .Normal)
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ extension UIImageView {
|
|||
}
|
||||
}
|
||||
|
||||
var isAnimating: Bool {
|
||||
return animatableImage?.isAnimating() ?? false
|
||||
var isAnimatingGIF: Bool {
|
||||
return animatableImage?.isAnimating() ?? isAnimating()
|
||||
}
|
||||
|
||||
var animatable: Bool {
|
||||
|
@ -39,15 +39,19 @@ extension UIImageView {
|
|||
}
|
||||
|
||||
// MARK: - Animation
|
||||
func startAnimating() {
|
||||
func startAnimatingGIF() {
|
||||
if animatable {
|
||||
animatableImage!.resumeAnimation()
|
||||
} else {
|
||||
startAnimating()
|
||||
}
|
||||
}
|
||||
|
||||
func stopAnimating() {
|
||||
func stopAnimatingGIF() {
|
||||
if animatable {
|
||||
animatableImage!.pauseAnimation()
|
||||
} else {
|
||||
stopAnimating()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue