Created
February 12, 2016 17:53
-
-
Save mingsai/c7a46d51b81bbad36f61 to your computer and use it in GitHub Desktop.
Swift class for managing UIView animations
This file contains hidden or 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
| // | |
| // MNGViewExtensions.swift | |
| // | |
| // | |
| // Created by Tommie N. Carter, Jr., MBA on 10/30/15. | |
| // Copyright © 2015 MING Technology. All rights reserved. | |
| // | |
| import UIKit | |
| extension UIView { | |
| func pauseAnimations() { | |
| let paused_time = self.layer.convertTime(CACurrentMediaTime(), fromLayer: nil) | |
| self.layer.speed = 0.0; | |
| self.layer.timeOffset = paused_time; | |
| } | |
| func resumeAnimations() { | |
| let paused_time = self.layer.timeOffset | |
| self.layer.speed = 1.0 | |
| self.layer.timeOffset = 0.0 | |
| self.layer.beginTime = 0.0 | |
| let time_since_pause = self.layer.convertTime(CACurrentMediaTime(), fromLayer: nil) - paused_time | |
| self.layer.beginTime = time_since_pause; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment