@@ -7,6 +7,7 @@
9import UIKit
9import UIKit
10+import TinyConstraints
11// MARK:- Controller with posts and channels availiable.
12// MARK:- Controller with posts and channels availiable.
12// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
13// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
@@ -34,6 +35,8 @@ class NewsController: UIViewController
35 navigationItem.searchController = searchController
36 navigationItem.searchController = searchController
36 definesPresentationContext = true
37 definesPresentationContext = true
39 override func viewWillAppear(_ animated: Bool) {
42 override func viewWillAppear(_ animated: Bool) {
@@ -72,6 +75,76 @@ class NewsController: UIViewController
72 @objc func addChannel(){
75 @objc func addChannel(){
73 print("Add channel")
76 print("Add channel")
79+ // for animating the banner
80+ var topConstraint: NSLayoutConstraint?
82+ let bannerView: UIView = {
84+ view.backgroundColor = .blue
85+ view.layer.cornerRadius = 25.0
86+ view.clipsToBounds = true
90+ let statusLabel: UILabel = {
91+ let label = UILabel()
93+ label.textColor = .white
94+ label.textAlignment = .center
98+ private func setUpBanner()
100+ view.addSubview(bannerView)
101+ bannerView.addSubview(statusLabel)
102+ statusLabel.edgesToSuperview()
104+ let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap(sender:)))
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!)
110+ bannerView.edgesToSuperview(excluding: [.bottom, .top, .left], insets: .right(20), usingSafeArea: true)
111+ bannerView.height(50)
112+ bannerView.width(50)
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)
123+ // animation for banner
124+ func changeConstraint(isVisible: Bool){
125+ topConstraint?.constant = isVisible ? 50 : -300
127+ UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseOut, animations: {
128+ self.view.layoutIfNeeded()
134+ var isBannerVisible: Bool = false
136+ func scrollViewDidScroll(_ scrollView: UIScrollView) {
137+ print(scrollView.contentOffset.y)
138+ if scrollView.contentOffset.y >= 50 && !isBannerVisible{
139+ isBannerVisible = true
140+ changeConstraint(isVisible: true)
143+ if isBannerVisible && scrollView.contentOffset.y == 0{
144+ isBannerVisible = false
145+ changeConstraint(isVisible: false)
77// MARK:- tableView delegate
150// MARK:- tableView delegate
@@ -126,4 +199,6 @@ extension NewsController: UITableViewDataSource
127 return view
200 return view