LeoNatan / LNPopupController

A framework for presenting view controllers as popups of other view controllers, much like the Apple Music and Podcasts apps.
MIT License
3.04k stars 342 forks source link

custom popup and dynamic height #354

Closed ghimireprashant closed 5 years ago

ghimireprashant commented 5 years ago

hello, Thanks for your wonderful help in maintaining this library you are a real life saver. Here is my problem. I am trying to present a custom docking view in tab bar but it still shows a default docking view while presenting in the tab bar. the code I have used is below. I am trying to change the height of the docking view in real-time but it still shows space when the height is changed. and also i want to know is there any way to access the property of docking view from other view controller? containingPopupBar.setNeedsLayout() containingPopupBar.layoutIfNeeded()

let customMapBar = UIStoryboard(name: "Custom", bundle: nil).instantiateViewController(withIdentifier: "CustomPopupBarViewController") as? CustomPopupBarViewController customMapBar?.view.backgroundColor = .clear // customMapBar.searchBar.delegate = self popupBar.customBarViewController = customMapBar! let popupContentController = UIStoryboard.songStoryboard.instantiateSongsPlayerViewController() popupContentView.popupCloseButtonStyle = .none popupInteractionStyle = .snap DispatchQueue.main.async { self.presentPopupBar(withContentViewController: popupContentController, animated: false, completion: nil) // self.tabBarController?.presentPopupBar(withContentViewController: popupContentController, animated: false, completion: nil) } https://drive.google.com/file/d/1b7XchrcB8fUJDItGT-cqq_66o_qfD56R/view?usp=sharing I have uploaded google drive project please check. @LeoNatan Please check the build

LeoNatan commented 5 years ago

Hello,

I am not sure I understand. Could you please post screenshots of the problem and perhaps mock ups of what you want to happen?

Also, please format your code.

Thanks

ghimireprashant commented 5 years ago

i will upload demo project shortly.

LeoNatan commented 5 years ago

I prefer we start with a description for your problem. I may not have time to look at the demo project. Thanks

ghimireprashant commented 5 years ago

something wrong with tabbar when i import library there is while inset in controller. i have uploaded some screen short. i want to present custom popup view in tabbar but it default when i use this code self.tabBarController?.presentPopupBar(withContentViewController: popupContentController, animated: false, completion: nil) but when i change this code to this self.presentPopupBar(withContentViewController: popupContentController!, animated: false, completion: nil) it is diplayed only in that controller i.e not in other controller that is in tabbar. also i want to change height dynamicly i have used self.preferredContentSize = CGSize(width: -1, height: self.view.frame.height - self.adView.frame.height) containingPopupBar.setNeedsLayout() containingPopupBar.layoutIfNeeded() it change the height for popup but the inset remains in that controller. i have attached image. Thanks. Simulator Screen Shot - iPhone Xʀ - 2019-09-08 at 19 52 36 Simulator Screen Shot - iPhone Xʀ - 2019-09-08 at 19 52 58 Simulator Screen Shot - iPhone Xʀ - 2019-09-08 at 19 53 03 Simulator Screen Shot - iPhone Xʀ - 2019-09-08 at 19 53 14

LeoNatan commented 5 years ago

So, if I understand correctly, you are seeing two different issues:

  1. The tab bar is incorrectly laid out when the tab bar controller is presenting the popup bar
  2. Changing the height of a custom popup bar controller doesn't correctly set the safe area insets of the presenting controllers

Are you able to reproduce these issues in the sample project? Also, please make sure you are using the latest version of the framework. I've seen this tab bar issue in the past, and it no longer reproduces in the latest versions.

LeoNatan commented 5 years ago

I just tested on the demo project. I displayed the map scene custom popup bar controller in the music app, which is presented on a tab bar controller. I then changed the height 2 seconds after presentation. Everything worked as expected:

Simulator Screen Shot - iPhone Xs Max - 2019-09-08 at 18 23 56 Simulator Screen Shot - iPhone Xs Max - 2019-09-08 at 18 24 01

ghimireprashant commented 5 years ago

yap it in the demo sample project. the tab bar laid out before presenting the popup bar. my problem is when i custom pop up bar in the tab bar it shows default popup bar not the custom bar that I have created. and also when I change the height of the custom popup bar in run time these the insect remains in controller. can you please provide me the code use you used to present in tabbar? thanks

LeoNatan commented 5 years ago

Here is my project with the changes:

Archive.zip

Open the "Music" scene.

ghimireprashant commented 5 years ago

i missed this part tabBarController?.popupBar.customBarViewController = customMapBar and was using popupBar.customBarViewController = customMapBar how can get access to custom view propert from other controller ? like title image and progress bar. thanks.

LeoNatan commented 5 years ago

Custom bars do not have images, progress bars or any other of the standard views. It's up to you to implement them.

ghimireprashant commented 5 years ago

is it there any way to cast popup bar controller? ie if let popUpItem = self.popupBar.customBarViewController as? CustomPopupBarViewController { popUpItem.imageView.image = albumArt } or if let popUpItem = self.tabBarController?.popupBar.customBarViewController as? CustomPopupBarViewController { popUpItem.imageView.image = albumArt } thanks

LeoNatan commented 5 years ago

Yes, of course.

StackHelp commented 4 years ago

@LeoNatan I am trying to set customBarViewController like below.

    let customPlayerBar = PlayerPopUpBarVC.instantiate()
    self.tabBarController?.popupBar.customBarViewController = customPlayerBar
    self.tabBarController?.presentPopupBar(withContentViewController: vc, openPopup: true, animated: true, completion: nil)

This does work however the problem is when I'm trying to get that like this code

    if let customItem = self.popupBar.customBarViewController as? PlayerPopUpBarVC {
        customItem.songTitleLabel.text = name
        customItem.songArtistLabel.text = artist
    }

I got nil for PlayerPopUpBarVC. Any idea why?

LeoNatan commented 4 years ago

I think you are trying to change the incorrect controller’s popup item.

StackHelp commented 4 years ago

@LeoNatan class PlayerPopUpBarVC: LNPopupCustomBarViewController. I have given PlayerPopUpBarVC as customBarViewController. Can you please elaborate more?

iDevelopper commented 4 years ago

You have to retrieve the popupBar in his container:

    if let customItem = self.tabBarController?.popupBar.customBarViewController as? PlayerPopUpBarVC {
        customItem.songTitleLabel.text = name
        customItem.songArtistLabel.text = artist
    }
StackHelp commented 4 years ago

@iDevelopper Still got nil

StackHelp commented 4 years ago

@LeoNatan Any solution for this pls? self.tabBarController?.popupBar.customBarViewController also gives nil