Advertisement
Guest User

Untitled

a guest
May 24th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // Arbeitsrapport
  4. //
  5. // Created by SITF NNagavci on 21.05.19.
  6. // Copyright © 2019 Swiss IT-Factory. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class MainViewController: UIViewController {
  12.  
  13. @IBOutlet weak var tableView: UITableView!
  14. @IBOutlet weak var mitUntrSwitch: UISwitch!
  15.  
  16. @IBOutlet weak var erstelltSwitch: UISwitch!
  17. @IBOutlet weak var headerView: UIView!
  18. var isExpanded = true
  19. @IBOutlet weak var headerViewTopConstraint: NSLayoutConstraint!
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22.  
  23. setupAttributedTitle()
  24. tableView.rowHeight = UITableView.automaticDimension
  25. tableView.separatorStyle = .none
  26. tableView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
  27. tableView.register(UINib(nibName: "MainCell", bundle: nil), forCellReuseIdentifier: "cell")
  28. setupHeaderViewLayout()
  29. self.navigationController?.navigationBar.setValue(true, forKey: "hidesShadow")
  30. self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
  31. self.navigationController?.navigationBar.shadowImage = UIImage()
  32. self.navigationController?.navigationBar.isTranslucent = true
  33. // Do any additional setup after loading the view.
  34.  
  35.  
  36. }
  37. func setupAttributedTitle() {
  38. let customView = UIView(frame: CGRect(x: 0, y: 0, width: 190, height: 30))
  39. let button = UIButton(type: .custom)
  40. button.setImage(UIImage(named: "expand-arrow"), for: .normal)
  41. button.addTarget(self, action: #selector(titleIconTap), for: .touchUpInside)
  42. button.clipsToBounds = true
  43. button.layer.cornerRadius = 4
  44. button.sizeToFit()
  45. button.frame = CGRect(x: 160, y: 0, width: 40, height: 30)
  46. let titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 170, height: 30))
  47. titleLabel.text = "Arbeitsrapport"
  48. titleLabel.font = UIFont.systemFont(ofSize: 24, weight: .semibold)
  49. customView.addSubview(titleLabel)
  50.  
  51. customView.addSubview(button)
  52. navigationItem.titleView = customView
  53. }
  54.  
  55. @objc func titleIconTap() {
  56. guard let button = navigationItem.titleView?.subviews[1] else { return }
  57.  
  58. UIView.animate(
  59. withDuration: 0.5,
  60. delay: 0.0,
  61. usingSpringWithDamping: 0.6,
  62. initialSpringVelocity: 1.8,
  63. options: .curveEaseOut,
  64. animations: {
  65. if self.isExpanded {
  66. self.headerViewTopConstraint.constant = -200
  67. self.headerView.isHidden = true
  68. self.headerView.alpha = 0
  69. button.transform = CGAffineTransform(rotationAngle: -CGFloat.pi)
  70. self.isExpanded = false
  71. }else{
  72. self.headerView.isHidden = false
  73. self.headerView.alpha = 1
  74. self.headerViewTopConstraint.constant = 0
  75. button.transform = CGAffineTransform.identity
  76. self.isExpanded = true
  77. }
  78. self.view.layoutIfNeeded()
  79. }
  80. )
  81.  
  82. }
  83. @IBAction func dismiss(_ sender: Any) {
  84. self.dismiss(animated: true, completion: nil)
  85. }
  86.  
  87. override func viewDidAppear(_ animated: Bool) {
  88. super.viewDidAppear(animated)
  89. // self.performSegue(withIdentifier: "showDetails", sender: self)
  90. erstelltSwitch.isOn = false;
  91. mitUntrSwitch.isOn = false;
  92.  
  93. }
  94.  
  95. func setupHeaderViewLayout() {
  96. headerView.layer.cornerRadius = 20
  97. headerView.layer.shadowColor = UIColor.darkGray.cgColor
  98. headerView.layer.shadowOpacity = 0.15
  99. headerView.layer.shadowRadius = 10
  100. headerView.layer.shadowOffset = CGSize.zero
  101. headerView.layer.shouldRasterize = true
  102. headerView.layer.rasterizationScale = UIScreen.main.scale
  103. }
  104.  
  105. }
  106.  
  107. extension MainViewController: UITableViewDelegate {
  108. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  109. performSegue(withIdentifier: "showDetails", sender: self)
  110. }
  111. }
  112.  
  113. extension MainViewController: UITableViewDataSource {
  114.  
  115. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  116.  
  117. let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MainCell
  118. cell.selectionStyle = .none
  119. if indexPath.row % 3 == 0 {
  120. cell.leftMarginConstraint.isActive = false
  121. cell.txtToHide.isHidden = true
  122.  
  123. cell.txtChangeTitle.title = "Von PSP"
  124. }else if indexPath.row % 3 == 1 {
  125. cell.leftMarginConstraint.isActive = false
  126. cell.txtToHide.isHidden = true
  127. cell.txtChangeTitle.title = "Nach PSP"
  128.  
  129. }else{
  130. cell.leftMarginConstraint.isActive = true
  131. cell.txtToHide.isHidden = false
  132. cell.txtChangeTitle.title = "INVENTAR NR"
  133.  
  134. }
  135. cell.containerView.backgroundColor = indexPath.row % 2 == 0 ? UIColor(red: 245.0/255, green: 251.0/255, blue: 255.0/255, alpha: 1.0) : .white
  136.  
  137.  
  138. return cell
  139. }
  140.  
  141. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  142. return 100//DataManager.shared.mainArray.count
  143. }
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement