Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // Arbeitsrapport
- //
- // Created by SITF NNagavci on 21.05.19.
- // Copyright © 2019 Swiss IT-Factory. All rights reserved.
- //
- import UIKit
- class MainViewController: UIViewController {
- @IBOutlet weak var tableView: UITableView!
- @IBOutlet weak var mitUntrSwitch: UISwitch!
- @IBOutlet weak var erstelltSwitch: UISwitch!
- @IBOutlet weak var headerView: UIView!
- var isExpanded = true
- @IBOutlet weak var headerViewTopConstraint: NSLayoutConstraint!
- override func viewDidLoad() {
- super.viewDidLoad()
- setupAttributedTitle()
- tableView.rowHeight = UITableView.automaticDimension
- tableView.separatorStyle = .none
- tableView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
- tableView.register(UINib(nibName: "MainCell", bundle: nil), forCellReuseIdentifier: "cell")
- setupHeaderViewLayout()
- self.navigationController?.navigationBar.setValue(true, forKey: "hidesShadow")
- self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
- self.navigationController?.navigationBar.shadowImage = UIImage()
- self.navigationController?.navigationBar.isTranslucent = true
- // Do any additional setup after loading the view.
- }
- func setupAttributedTitle() {
- let customView = UIView(frame: CGRect(x: 0, y: 0, width: 190, height: 30))
- let button = UIButton(type: .custom)
- button.setImage(UIImage(named: "expand-arrow"), for: .normal)
- button.addTarget(self, action: #selector(titleIconTap), for: .touchUpInside)
- button.clipsToBounds = true
- button.layer.cornerRadius = 4
- button.sizeToFit()
- button.frame = CGRect(x: 160, y: 0, width: 40, height: 30)
- let titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 170, height: 30))
- titleLabel.text = "Arbeitsrapport"
- titleLabel.font = UIFont.systemFont(ofSize: 24, weight: .semibold)
- customView.addSubview(titleLabel)
- customView.addSubview(button)
- navigationItem.titleView = customView
- }
- @objc func titleIconTap() {
- guard let button = navigationItem.titleView?.subviews[1] else { return }
- UIView.animate(
- withDuration: 0.5,
- delay: 0.0,
- usingSpringWithDamping: 0.6,
- initialSpringVelocity: 1.8,
- options: .curveEaseOut,
- animations: {
- if self.isExpanded {
- self.headerViewTopConstraint.constant = -200
- self.headerView.isHidden = true
- self.headerView.alpha = 0
- button.transform = CGAffineTransform(rotationAngle: -CGFloat.pi)
- self.isExpanded = false
- }else{
- self.headerView.isHidden = false
- self.headerView.alpha = 1
- self.headerViewTopConstraint.constant = 0
- button.transform = CGAffineTransform.identity
- self.isExpanded = true
- }
- self.view.layoutIfNeeded()
- }
- )
- }
- @IBAction func dismiss(_ sender: Any) {
- self.dismiss(animated: true, completion: nil)
- }
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
- // self.performSegue(withIdentifier: "showDetails", sender: self)
- erstelltSwitch.isOn = false;
- mitUntrSwitch.isOn = false;
- }
- func setupHeaderViewLayout() {
- headerView.layer.cornerRadius = 20
- headerView.layer.shadowColor = UIColor.darkGray.cgColor
- headerView.layer.shadowOpacity = 0.15
- headerView.layer.shadowRadius = 10
- headerView.layer.shadowOffset = CGSize.zero
- headerView.layer.shouldRasterize = true
- headerView.layer.rasterizationScale = UIScreen.main.scale
- }
- }
- extension MainViewController: UITableViewDelegate {
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- performSegue(withIdentifier: "showDetails", sender: self)
- }
- }
- extension MainViewController: UITableViewDataSource {
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MainCell
- cell.selectionStyle = .none
- if indexPath.row % 3 == 0 {
- cell.leftMarginConstraint.isActive = false
- cell.txtToHide.isHidden = true
- cell.txtChangeTitle.title = "Von PSP"
- }else if indexPath.row % 3 == 1 {
- cell.leftMarginConstraint.isActive = false
- cell.txtToHide.isHidden = true
- cell.txtChangeTitle.title = "Nach PSP"
- }else{
- cell.leftMarginConstraint.isActive = true
- cell.txtToHide.isHidden = false
- cell.txtChangeTitle.title = "INVENTAR NR"
- }
- cell.containerView.backgroundColor = indexPath.row % 2 == 0 ? UIColor(red: 245.0/255, green: 251.0/255, blue: 255.0/255, alpha: 1.0) : .white
- return cell
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 100//DataManager.shared.mainArray.count
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement