Guest User

Untitled

a guest
May 21st, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. import UIKit
  2.  
  3. class ViewController: UIViewController
  4. {
  5.  
  6. var one: [UIImage] = []
  7. var two: [UIImage] = []
  8.  
  9.  
  10.  
  11. override func viewDidLoad()
  12. {
  13. super.viewDidLoad()
  14.  
  15. one = createImageArray(total: 20, imagePrefix: "images1")
  16. two = createImageArray(total: 20, imagePrefix: "images2")
  17.  
  18. UIView.animateKeyframes(withDuration: 3.0, delay: 0.0, options: [], animations: {
  19. UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 3, animations: {
  20. self.animatingImage.animationImages = self.one
  21. self.animatingImage.animationDuration = 2
  22. self.animatingImage.startAnimating()
  23. })
  24.  
  25. UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 3, animations: {
  26. self.animatingImage.animationImages = self.two
  27. self.animatingImage.animationDuration = 2
  28. self.animatingImage.startAnimating()
  29. })
  30.  
  31. }, completion:{ _ in
  32. print("end")
  33. })
  34. }
  35.  
  36. override func didReceiveMemoryWarning()
  37. {
  38. super.didReceiveMemoryWarning()
  39. }
  40.  
  41. func createImageArray(total: Int, imagePrefix: String) -> [UIImage]
  42. {
  43. var imageArray: [UIImage] = []
  44.  
  45. for imageCount in 1...total
  46. {
  47. let imageName = "(imagePrefix)(imageCount).jpg"
  48. let image = UIImage(named: "(imageName)")!
  49. imageArray.append(image)
  50. }
  51.  
  52. return imageArray
  53. }
  54.  
  55.  
  56. @IBOutlet weak var animatingImage: UIImageView!
  57.  
  58. }
  59.  
  60. self.animatingImage = UIImage.animatedImage(with: one, duration: 1)
  61.  
  62. // animate after 1 sec
  63. DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
  64. let animatedImage = UIImage.animatedImage(with: two, duration: 1)
  65. }
Add Comment
Please, Sign In to add comment