Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Container Controller
- import Foundation
- import UIKit
- class ContainerController: UIViewController {
- // MARK: Properties
- private var aboutController: AboutViewController!
- private var slideController: SlideController!
- public var centerController: UINavigationController!
- public let homeController = HomeScreenController()
- // Delegates
- public weak var blurEffectBooleanDelegate: BlurEffectBooleanProtocol?
- // Slide Menu Toggle
- private var isOpen: Bool = false
- override func viewDidLoad() {
- super.viewDidLoad()
- setup()
- configureHomeNavigationController()
- }
- private func setup() {
- view.backgroundColor = UIColor(red: 65/255, green: 0, blue: 0, alpha: 1.0)
- }
- private func configureHomeNavigationController() {
- centerController = UINavigationController(rootViewController: homeController)
- homeController.handleSlideMenuDelegate = self
- self.blurEffectBooleanDelegate = homeController
- view.addSubview(centerController.view)
- addChild(centerController)
- centerController.didMove(toParent: self)
- }
- private func configureAboutController() {
- aboutController = AboutViewController()
- view.insertSubview(aboutController.view, at: 0)
- addChild(aboutController)
- aboutController.didMove(toParent: self)
- }
- // MARK: TEST - Status: DONE
- fileprivate func addSlideMenu() {
- if slideController == nil {
- slideController = SlideController()
- view.insertSubview(slideController.view, at: 0)
- addChild(slideController)
- slideController.didMove(toParent: self)
- }
- }
- // MARK: TEST - Status: DONE
- fileprivate func removeSlideMenu() {
- if slideController != nil {
- slideController.view.removeFromSuperview()
- slideController.willMove(toParent: nil)
- slideController.removeFromParent()
- slideController = nil
- }
- }
- public func shouldExpandSlideMenu(_ expanded: Bool) {
- if expanded {
- UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.5, options: .curveEaseInOut, animations: {
- self.centerController.view.frame.origin.x = self.centerController.view.frame.width - 100
- self.blurEffectBooleanDelegate?.blurEnabled = !expanded
- self.addSlideMenu()
- }, completion: nil)
- } else {
- UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.5, options: .curveEaseInOut, animations: {
- self.centerController.view.frame.origin.x = 0
- self.blurEffectBooleanDelegate?.blurEnabled = !expanded
- }, completion: { _ in
- self.removeSlideMenu()
- })
- }
- }
- }
- extension ContainerController: HandleSlideMenuProtocol {
- func handleSlideToggle() {
- isOpen = !isOpen
- shouldExpandSlideMenu(isOpen)
- }
- }
- // Home Controller
- import UIKit
- import Foundation
- class HomeScreenController: UIViewController, BlurEffectBooleanProtocol {
- // References / Properties
- public var apiManager = APINetworkManager.shared
- public lazy var mainView = MainScreenView()
- public var detailController = DetailViewController()
- public var launchScreenController = LaunchScreenController()
- public lazy var internetNetwork = InternetNetwork(parent: self)
- private var blurEffectView = UIVisualEffectView()
- // Delegates
- public weak var launchScreenDelegate: LaunchScreenProtocol?
- public weak var castMovieIdDelegate: CastMovieIdProtocol?
- public weak var handleSlideMenuDelegate: HandleSlideMenuProtocol?
- // Delegate Properties
- var blurEnabled: Bool = true
- override func loadView() {
- view = mainView
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- internetNetwork.checkForInternetConnectivity()
- initialSetup()
- makeApiCall()
- }
- private func makeApiCall() {
- launchScreenDelegate = launchScreenController
- navigationController?.pushViewController(launchScreenController, animated: false)
- makeRequestToServer()
- }
- private func makeRequestToServer() {
- apiManager.makeApiRequest {
- self.leftBarButtonView()
- self.mainView.refreshControl.endRefreshing()
- self.launchScreenDelegate?.isLoadingFinished(true)
- DispatchQueue.main.async { [weak self] in
- guard let self = self else { return }
- for cell in self.mainView.collectionView.visibleCells {
- if let cell = cell as? MovieCollectionViewCell {
- cell.innerCollectionView.reloadData()
- }
- }
- }
- }
- }
- // MARK: - Setup
- private func initialSetup() {
- // Navigation Controller
- navigationController?.isNavigationBarHidden = false
- let titleAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
- navigationController?.navigationBar.titleTextAttributes = titleAttributes
- navigationController?.navigationBar.topItem?.title = "Movies"
- navigationController?.navigationBar.prefersLargeTitles = false
- navigationController?.hidesBarsOnSwipe = false
- navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "HelveticaNeue-Thin", size: 50)!, NSAttributedString.Key.foregroundColor: UIColor(red: 225/255, green: 225/255, blue: 225/255, alpha: 1.0)]
- navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
- navigationController?.navigationBar.shadowImage = UIImage()
- navigationController?.navigationBar.isTranslucent = true
- // Blur Effect
- blurEffectView.effect = mainView.blurEffect
- blurEffectView.frame = view.bounds
- blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
- blurEffectView.isHidden = true
- blurEffectView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(blurEffectTap)))
- view.insertSubview(blurEffectView, at: 1)
- // Refresh Control
- mainView.refreshControl.addTarget(self, action: #selector(refreshView), for: .valueChanged)
- }
- private func leftBarButtonView() {
- navigationItem.leftBarButtonItem = UIBarButtonItem(image: mainView.categoryImageView.image, style: .plain, target: self, action: #selector(categoryAction))
- }
- private func blurEffectTransition() {
- blurEffectView.isHidden = blurEnabled
- }
- // MARK: - Refresh Control
- @objc private func refreshView() {
- makeRequestToServer()
- }
- private func displayingDetailController() {
- self.navigationController?.pushViewController(detailController, animated: true)
- }
- // MARK: Actions
- @objc private func blurEffectTap() {
- handleSlideMenuDelegate?.handleSlideToggle()
- blurEffectTransition()
- }
- @objc private func categoryAction() {
- handleSlideMenuDelegate?.handleSlideToggle()
- blurEffectTransition()
- }
- } // Class end
- // This is the issue Here in this extension. I get no bug or anything just nil navigationController
- // MARK: Cell Selection Extension
- extension HomeScreenController: InnerSelectedCellProtocol {
- func selectedCell(isSelected: Bool) {
- if isSelected == true {
- // Here
- // This is a protocol from a UICollectionViewDelegate of didSelectItemAt() in a separate file. It uses dependency injection when being initialized and its assigned to the HomeController.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement