// // ViewController.swift // MKRingProgressViewExample // // Created by Max Konovalov on 20/10/15. // Copyright © 2015 Max Konovalov. All rights reserved. // import UIKit class ViewController: UIViewController { @IBOutlet weak var groupContainerView: UIView! @IBOutlet weak var progressGroup: RingProgressGroupView! @IBOutlet weak var iconsHeightConstraint: NSLayoutConstraint! var buttons = [RingProgressGroupButton]() var selectedIndex = 0 override func viewDidLoad() { super.viewDidLoad() let containerView = UIView(frame: navigationController!.navigationBar.bounds) navigationController!.navigationBar.addSubview(containerView) // These are optional and only serve to improve accessibility progressGroup.ring1.accessibilityLabel = NSLocalizedString("Move", comment: "") progressGroup.ring2.accessibilityLabel = NSLocalizedString("Exercise", comment: "") progressGroup.ring3.accessibilityLabel = NSLocalizedString("Stand", comment: "") let n = 7 for i in 0.. selectedIndex) ? -self.view.frame.width : self.view.frame.width buttons[selectedIndex].isSelected = false sender.isSelected = true selectedIndex = newIndex UIView.animate(withDuration: 0.2, delay: 0.0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.0, options: [], animations: { () -> Void in self.groupContainerView.transform = CGAffineTransform(translationX: dx, y: 0) }) { (_) -> Void in self.groupContainerView.transform = CGAffineTransform(translationX: -dx, y: 0) self.progressGroup.ring1.progress = 0.0 self.progressGroup.ring2.progress = 0.0 self.progressGroup.ring3.progress = 0.0 UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.0, options: [], animations: { () -> Void in self.groupContainerView.transform = CGAffineTransform.identity }, completion: { (_) -> Void in self.updateMainGroupProgress() }) } } private func updateButtonsProgress() { UIView.animate(withDuration: 0.5) { for button in self.buttons { button.contentView.ring1.progress = Double(arc4random() % 200) / 100.0 button.contentView.ring2.progress = Double(arc4random() % 200) / 100.0 button.contentView.ring3.progress = Double(arc4random() % 200) / 100.0 } } } private func updateMainGroupProgress(delay: TimeInterval = 0.0) { let selectedGroup = buttons[selectedIndex] UIView.animate(withDuration: 1.0, delay: delay, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.0, options: [], animations: { self.progressGroup.ring1.progress = selectedGroup.contentView.ring1.progress self.progressGroup.ring2.progress = selectedGroup.contentView.ring2.progress self.progressGroup.ring3.progress = selectedGroup.contentView.ring3.progress }, completion: nil) } @IBAction func randomize(_ sender: AnyObject? = nil) { updateButtonsProgress() updateMainGroupProgress() } }