Guest User

Untitled

a guest
Jan 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. class CreatedSessionViewController: UIViewController {
  2.  
  3. var createdSession: [YogaPose]!
  4. var poseDuration: Double = 20.00
  5. var timer = NSTimer!()
  6. var currentPoseIndex = 1
  7.  
  8. //Outlets:
  9. @IBOutlet var poseProgressView: UIProgressView!
  10. @IBOutlet var lblPoseCount: UILabel!
  11. @IBOutlet var lblPoseName: UILabel!
  12. @IBOutlet var imgPose: UIImageView!
  13. @IBOutlet var tvDescription: UITextView!
  14.  
  15. // Do any additional setup after loading the view:
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18.  
  19. displayFirstPoseInArray()
  20. }
  21.  
  22. func displayFirstPoseInArray(){
  23. lblPoseCount.text = (String(currentPoseIndex) + "/" + String(createdSession.count))
  24. lblPoseName.text = createdSession[0].title
  25. imgPose.image = UIImage(named: String(format: "%d.jpg", (createdSession[0].id)!))
  26. tvDescription.text = createdSession[0].desc
  27. }
  28.  
  29. @IBAction func btnPlaySession(sender: AnyObject) {
  30. timer = NSTimer.scheduledTimerWithTimeInterval(poseDuration, target: self, selector: "getNextPoseData", userInfo: nil, repeats: true)
  31. }
  32.  
  33. func getNextPoseData(){
  34. if (currentPoseIndex < createdSession.count){
  35.  
  36. setProgressBar()
  37.  
  38. lblPoseCount.text = (String(currentPoseIndex + 1) + "/" + String(createdSession.count))
  39. lblPoseName.text = createdSession[currentPoseIndex].title
  40. imgPose.image = UIImage(named: String(format: "%d.jpg",(createdSession[currentPoseIndex].id)!))
  41. tvDescription.text = createdSession[currentPoseIndex].desc
  42. currentPoseIndex += 1
  43. print(currentPoseIndex)
  44. }
  45. }
  46.  
  47. func setProgressBar(){
  48.  
  49.  
  50. }
  51.  
  52. class ViewController: UIViewController
  53. {
  54. @IBOutlet weak var progressBar: UIProgressView!
  55. var timer = NSTimer!()
  56. var poseDuration = 20
  57. var indexProgressBar = 0
  58. var currentPoseIndex = 0
  59.  
  60. override func viewDidLoad()
  61. {
  62. super.viewDidLoad()
  63.  
  64. // initialise the display
  65. progressBar.progress = 0.0
  66. }
  67.  
  68.  
  69. @IBAction func cmdGo(sender: AnyObject)
  70. {
  71. // display the first pose
  72. getNextPoseData()
  73.  
  74. // start the timer
  75. timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "setProgressBar", userInfo: nil, repeats: true)
  76. }
  77.  
  78. func getNextPoseData()
  79. {
  80. // do next pose stuff
  81. currentPoseIndex += 1
  82. print(currentPoseIndex)
  83. }
  84.  
  85. func setProgressBar()
  86. {
  87. if indexProgressBar == poseDuration
  88. {
  89. getNextPoseData()
  90.  
  91. // reset the progress counter
  92. indexProgressBar = 0
  93. }
  94.  
  95. // update the display
  96. // use poseDuration - 1 so that you display 20 steps of the the progress bar, from 0...19
  97. progressBar.progress = Float(indexProgressBar) / Float(poseDuration - 1)
  98.  
  99. // increment the counter
  100. indexProgressBar += 1
  101. }
  102. }
  103.  
  104. func setProgress() {
  105. time += 0.1
  106. ProgressBar.setProgress(time / 3, animated: true)
  107. if time >= 3 {
  108. self.time = 0.01
  109. ProgressBar.progress = 0
  110. let color = self.downloadProgressBar.progressTintColor
  111. self.downloadProgressBar.progressTintColor = self.downloadProgressBar.trackTintColor
  112. self.downloadProgressBar.trackTintColor = color
  113. }
Add Comment
Please, Sign In to add comment