@@ -7,6 +7,7 @@
77//
88
99import UIKit
10+import TinyConstraints
1011
1112// MARK:- Controller with posts and channels availiable.
1213// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
@@ -34,6 +35,8 @@ class NewsController: UIViewController
3435
3536 navigationItem.searchController = searchController
3637 definesPresentationContext = true
38+
39+ setUpBanner()
3740 }
3841
3942 override func viewWillAppear(_ animated: Bool) {
@@ -72,6 +75,76 @@ class NewsController: UIViewController
7275 @objc func addChannel(){
7376 print("Add channel")
7477 }
78+
79+ // for animating the banner
80+ var topConstraint: NSLayoutConstraint?
81+
82+ let bannerView: UIView = {
83+ let view = UIView()
84+ view.backgroundColor = .blue
85+ view.layer.cornerRadius = 25.0
86+ view.clipsToBounds = true
87+ return view
88+ }()
89+
90+ let statusLabel: UILabel = {
91+ let label = UILabel()
92+ label.text = "-"
93+ label.textColor = .white
94+ label.textAlignment = .center
95+ return label
96+ }()
97+
98+ private func setUpBanner()
99+ {
100+ view.addSubview(bannerView)
101+ bannerView.addSubview(statusLabel)
102+ statusLabel.edgesToSuperview()
103+
104+ let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap(sender:)))
105+
106+ bannerView.addGestureRecognizer(tap)
107+ topConstraint = NSLayoutConstraint(item: bannerView, attribute: .top, relatedBy: .equal, toItem: view.safeAreaLayoutGuide, attribute: .top, multiplier: 1, constant: -300)
108+ view.addConstraint(topConstraint!)
109+
110+ bannerView.edgesToSuperview(excluding: [.bottom, .top, .left], insets: .right(20), usingSafeArea: true)
111+ bannerView.height(50)
112+ bannerView.width(50)
113+ }
114+
115+ // when table is scrolling no deletion is availiable
116+ @objc func handleTap(sender: UITapGestureRecognizer? = nil) {
117+ let indexPath = IndexPath(row: 0, section: 0)
118+ self.tableView.scrollToRow(at: indexPath, at: .top, animated: true)
119+// isBannerVisible = false
120+// changeConstraint(isVisible: false)
121+ }
122+
123+ // animation for banner
124+ func changeConstraint(isVisible: Bool){
125+ topConstraint?.constant = isVisible ? 50 : -300
126+
127+ UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseOut, animations: {
128+ self.view.layoutIfNeeded()
129+ }) { (completed) in
130+
131+ }
132+ }
133+
134+ var isBannerVisible: Bool = false
135+
136+ func scrollViewDidScroll(_ scrollView: UIScrollView) {
137+ print(scrollView.contentOffset.y)
138+ if scrollView.contentOffset.y >= 50 && !isBannerVisible{
139+ isBannerVisible = true
140+ changeConstraint(isVisible: true)
141+ }
142+
143+ if isBannerVisible && scrollView.contentOffset.y == 0{
144+ isBannerVisible = false
145+ changeConstraint(isVisible: false)
146+ }
147+ }
75148}
76149
77150// MARK:- tableView delegate
@@ -126,4 +199,6 @@ extension NewsController: UITableViewDataSource
126199
127200 return view
128201 }
202+
203+
129204}