Apologies
You must be signed in to watch this lesson.
Play Episode Maximizing Animation
Podcasts
In the last lesson, we were able to execute a few animations to minimize and maximize our player view. In today's video, let's go over how to hook up our player view with the episode that we are trying to play in EpisodesController. In order to do this, we'll access our MainTabBarController instance through the UIApplication.shared singleton instance. Once you understand how this works, everything should be quite straightforward and easy to implement. Enjoy.

Comments (11)
meher
5 years ago
Hi Brian, Why don't we create a delegate of type "MainTabBarController" in "PlayerDetailsView" and assign it to self from "MainTabBarController" instead of capturing the "MainTabBarController" using "rootViewController" ? Is there a specific reason for capturing the rootViewController from keyWindow instead of using delegates?
Brian Voong
5 years ago
meher
5 years ago
Thank you Brian i know another way of doing it now,you are the best
rick27
5 years ago
meher or brian, Can you further explain this concept using code examples. In one of my projects, I'm not using MainTabBarController as my rootViewController. I'm getting nil for mainTabBarController inside of didSelectRowAt. I've also tried instantiating a new instance MainTabBarController() to no avail. The podcast does play but there's no PlayerDetailsView presented to the screen. Brian - I was also checking out your Audible series about Protocols and Custom Delegation where you encountered a similar problem, but I can't quite translate it to fix this problem. Any help would be appreciated.
Brandon Cao
5 years ago
Hi Brian, I'm having an issue with the mini player view covering the cells at the bottom of my table view. Is there a way to fix this? Thanks
Brian Voong
5 years ago
SimonQ
5 years ago
Whenever I try to select another podcast the entire app crashes and I get this error: ``` Thread 1: Fatal error: Double value cannot be converted to Int because it is either infinite or NaN ``` inside the CMTime extension Is there a fix for this later on?
Brian Voong
5 years ago
SimonQ
5 years ago
Awesome! That fixed the issue. However another problem arises now where the podcast does not play at all after selecting another podcast to listen to. Is this an issue with the existing player instance that is not de-initialized?
SimonQ
5 years ago
Odd, it works now!
Brian Voong
5 years ago
ZeroSingularity
5 years ago
I'm loving these videos and by far the best course purchase I've ever made!! I'm getting the same error as @SimonQ even after the check in the CMTime extension Am I missing something? import AVKit extension CMTime { func toDisplayString() -> String { let totalSeconds = Int(CMTimeGetSeconds(self)) let seconds = totalSeconds % 60 let minutes = totalSeconds / 60 let timeFormatString = String(format: "%02d:%02d", minutes, seconds) return timeFormatString } }
ZeroSingularity
5 years ago
The solution is in the beginning of the next video! Thank you Brian!
joker45
5 years ago
Hey Brian, can you maybe explain if you have time why A) not works but B) does? Thank you very much. A) let mainTabBarController = MainTabBarController() mainTabBarController.minimizePlayerDetails() B) let mainTabBarController = UIApplication.shared.keyWindow?.rootViewController as?MainTabBarController mainTabBarController?.minimizePlayerDetails()
ravikanth.marri@gmail.com
5 years ago
Hi joker45 , In Option A , You are creating a new MainTabBarController which is not our application's rootViewController , So you will not see any change.
ravikanth.marri@gmail.com
5 years ago
Hi Brian, Great lesson. Is there any particular reason for implementing the animations of "PlayerDetailsView" in "MainTabBarController" ? The usage of the animations is in PlayerDetailsView , so why not implement in the same class ?
ravikanth.marri@gmail.com
5 years ago
Sorry , I mean Why not in "EpisodesController" , where we initially created "PlayerDetailsView".
azemii
4 years ago
Hey Brian, I was wondering why we did the implementation for the maximized and minimized playerdetailsview in the mainTabBar controller and not just do that inside of the playerdetailsView? Is there a specific reason for that or are both implementations just as viable? Best regards
Brian Voong
4 years ago
Allen Hinson
3 years ago
Hey Brian, I am trying to follow along the tutorial but when I get to the part of implementing the minimizeplayerdetail function inside the handleDismiss action but nothing is happening when I click the dismiss button. I know the button is set up properly because it worked when originally had the other function to remove the entire view. I'm not sure why it is doing this for me. I keep getting a warning saying "'keyWindow' was deprecated in iOS 13.0: Should not be used for applications that support multiple scenes as it returns a key window across all connected scenes" but I'm not sure how to fix that. Any idea what is going on?
Brian Voong
3 years ago
Allen Hinson
3 years ago
Hi Brain, I implemented the suggested code form the github link you provided. It is working to where I press the dismiss button and it minimizes the view, however there are a few problems that came with this. The first is that when the view minimizes, not only is it minimizing the playerDetailView but it also minimizing the mainTabBar view as-well so it shows a black screen and the tabBar on the bottom becomes an empty view with not TabBar buttons. Also when it minimizes, after a second it maximizes again without me pressing the view manually. I am comparing code and I have set up everything like yours so I'm not sure why I am getting this error.
Allen Hinson
3 years ago
Not sure if you saw my last message but I am still having some problems with calling the minimize and maximize functions from the tabBar into the PlayerDetailView controller. I have tried the solution above from github but instead of minimizing just the PlayerDetailView it minimizes all my views and leaves a black screen. I have tried this: guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let sceneDelegate = windowScene.delegate as? SceneDelegate else { return } let storyboard = UIStoryboard(name: "Main", bundle: nil) let controller = storyboard.instantiateViewController(withIdentifier: "MainTabBarController") as! TabBarController controller.selectedIndex = PlayerDetailController.selectedIndex ?? 0 sceneDelegate.window?.rootViewController = controller controller.maximizePlayerDetails() While it works, it is not as fluid and smooth as your minimize and maximize functions. I have downloaded your source code and it still shows that it is utilizing keyWindow but when I try to use that code in my dismissal button, it does nothing and the view doesn't minimize. I'm not sure if anyone else has had this problem but it has left me stuck for quite a while.
Allen Hinson
3 years ago
Also the above function for some reason refreshes all my viewcontrollers which leaves them changing to a weird lay out
Ally Makongo
3 years ago
Hi Brian, I have tested my code and your code they behave the same. Upon minimizing they tend to align above the middle and not the bottom(above the tabBar). M running on 11.4.1 Xcode Swift 5
saad
3 years ago
New Fix ? let mainTabBarController = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController as? MainTabBarController
saad
3 years ago
New Fix ⚙️ For Swift 5 IOS 14 Instead of using this = self.tabBar.transform = CGAffineTransform(translationX: 0, y: 100) Replace with this. = self.tabBar.frame.origin.y = self.view.frame.size.height
el
3 years ago
Thank you , it helped . Good luck
saad
3 years ago
HELP & SUPPORT