TabBarController.swift
1import UIKit 2class TabBarController:UITabBarController{ 3 4 override func viewDidLoad() { 5 super.viewDidLoad() 6 mainSetUp() 7 8 UITabBar.appearance().tintColor = .green 9 } 10 11 func mainSetUp() { 12 var viewControllers = [UIViewController]() 13 14 let firstViewController = ViewController() 15 let thirdViewController = ViewController2() 16 17 let firstNavigationController = UINavigationController(rootViewController: firstViewController) 18 let thirdNavigationController = UINavigationController(rootViewController: thirdViewController) 19 20 firstNavigationController.tabBarItem = UITabBarItem(tabBarSystemItem: .bookmarks, tag: 1) 21 22 thirdNavigationController.tabBarItem = UITabBarItem(tabBarSystemItem: .contacts, tag: 1) 23 24 25 26 viewControllers.append(thirdNavigationController) 27 viewControllers.append(firstNavigationController) 28 29 30 self.setViewControllers(viewControllers, animated: false) 31 } 32} 33
ViewCOntroller.swift
1import UIKit 2 3class ViewController:UIViewController{ 4 5 var progressView:UIProgressView! 6 var progressArray:[UIProgressView] = [] 7 8 override func viewWillAppear(_ animated: Bool) { 9 super.viewWillAppear(animated) 10 11 progressBarView() 12 for i in 0 ..< progressArray.count{ 13 progressArray[i].setProgress(0.2, animated: true) 14 } 15 16 17 } 18 19 override func viewDidLoad() { 20 21 super.viewDidLoad() 22 23 self.view.backgroundColor = #colorLiteral(red: 0.8930925727, green: 0.893242538, blue: 0.8930727839, alpha: 1) 24 25 self.navigationItem.title = "タイトル" 26 self.navigationController?.navigationBar.barTintColor = .blue 27 self.navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white, .font: UIFont.systemFont(ofSize: self.view.bounds.width / 22, weight: .bold)] 28 29 } 30 31 func progressBarView(){ 32 33 let minprogress = self.view.bounds.width / 12 34 let interval = (self.view.bounds.height / 17 * 8) - (self.view.bounds.height / 18 * 8) 35 let progressInterval = (self.view.bounds.height / 17 * 8 + minprogress + interval) - (self.view.bounds.height / 17 * 8) - 4 36 37 //プログレスのラベル 38 for i in 0 ... 6{ 39 progressView = UIProgressView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.height / 3 + self.view.bounds.width / 10, height: self.view.bounds.width / 10)) 40 progressView.center = CGPoint(x: self.view.bounds.width / 2, y: self.view.bounds.height / 17 * 8 + progressInterval * CGFloat(i) + 10) 41 42 progressView.transform = CGAffineTransform(scaleX: 1.0, y: 5.0) 43 progressView.trackTintColor = .lightGray 44 progressView.progressViewStyle = .default 45 progressView.progressTintColor = .blue 46 self.view.addSubview(progressView) 47 progressArray.append(progressView) 48 49 } 50 51 52 } 53 54} 55
ViewCOntroller2.swift
1import UIKit 2class ViewController2:UIViewController{ 3 4 override func viewDidLoad() { 5 super.viewDidLoad() 6 self.view.backgroundColor = .white 7 } 8 9} 10
なぜprogressViewのアニメーションが最初灰色のviewもアニメーションされてしまうのでしょうか?そして、青色のゲージのアニメーションの仕方が不自然な気がするのですが、これを直すことはできますでしょうか?
あなたの回答
tips
プレビュー