Apologies
You must be signed in to watch this lesson.
Animations and Monitor Start Time
Podcasts
One unique thing about the Podcasts application is that whenever an episode starts to play, you get a nice bouncy animation of the episode's image. In today's lesson, we look at how to perform this animation using transforms through CGAffineTransform. Next we'll monitor when the player begins playing of our audio stream for each episode. Once we figure out how this works, we'll put it all together and complete this feature.

Comments (14)
fiftysoft
6 years ago
how much take time the next episode to release ?
Brian Voong
6 years ago
fiftysoft
6 years ago
good luck
Dew Douglass
5 years ago
Thanks for the hard work brian. You ought to make a meta video one day where you explain how to make a video explaining how to code.
Tube
6 years ago
I thought you were going to inject some functional programming into our lesson when you created shrunkenTransform. I went ahead and just passed the transform into: func animateImageViewTransform(_ transform: CGAffineTransform)
Brian Voong
6 years ago
azemii
4 years ago
Super clean, thanks!
zcrystal
6 years ago
Hey Brian, I don't really understand the CMTimeMake function. Why did you choose 3 as the timescale?
azemii
4 years ago
1 year later, but maybe someone else might read this. CMTime t1 = CMTimeMake(1, 10); // 1/10 second = 0.1 second CMTime t2 = CMTimeMake(2, 1); // 2 seconds CMTime t3 = CMTimeMake(3, 4); // 3/4 second = 0.75 second CMTime t4 = CMTimeMake(6, 8); // 6/8 second = 0.75 second So Brians example will run the block of code, enlarge the image, 0.3 seconds after the audio started playing. Example code taken from stack.
Alpensol
6 years ago
Hey Brain, Are we not creating a reference cycle on the player.addBoundaryTimeObserver closure, since the View owns the player object that owns the closure and the closure then points back to the view. I am presuming we would use "unowned" since we know for sure that the view will always exist when this closure activate ?
Huo En Ci
6 years ago
Hi Brian, Would you say that AwakeFromNib is quite the same as viewWillAppear or didLayoutSubviews? Also I'm curious as to why you use use a UIView for (PlayerDetailsView), instead of a UIViewController, which you can do a presentViewController method instead?
Brian Voong
6 years ago
antdwash
5 years ago
Hi, Brain So I created the entire podcast player view programmatically instead of using Nib files. I'm using the method 'didMoveToSuperview' instead of 'awakeFromNib' to set the time observer for the AVPlayer. Do you have any ideas why the AVPlayer is still playing the podcast audio in the background after clicking dismiss button?
antdwash
5 years ago
Later video solved it =]
Dew Douglass
5 years ago
Hey dude what are the main functions you used to layout the views programmatically? Did you use stackviews?
simran5590
5 years ago
Also you can do: #if DEBUG searchBar(searchController?.searchBar, textDidChange: "Fragmented Podcast") #endif This will only search when you are in DEBUG mode.
Dew Douglass
5 years ago
Hold up dude did you get a new apartment, new setup? haha
nombienombie
5 years ago
Hey Brian, another great video! I was able to refactor the animation code even further to reduce duplication. I did something along the lines of: fileprivate func shrinkImageView() -> Void { self.animateEpisodeArtwork { self.episodePlayerArtwork.transform = CGAffineTransform(scaleX: 0.7, y: 0.7) } } fileprivate func enlargeImageView() -> Void { self.animateEpisodeArtwork { self.episodePlayerArtwork.transform = .identity } } fileprivate func animateEpisodeArtwork(withAnimtaion animations: @escaping () -> Void) -> Void { UIView.animate(withDuration: 0.75, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .curveEaseOut, animations: animations, completion: nil) }
Maxnelson997
5 years ago
That taper fade animation haha.
shender ramos
4 years ago
great tutorial man... i am learning so many little things from this course.. i cant wait till jump on to the next one....
Muhammad Junaid
4 years ago
I am doing it programmatically , what is the alternative of awakefromNib()?
Brian Voong
4 years ago
Muhammad Junaid
4 years ago
Thanks brian
Ally Makongo
3 years ago
Instance member 'player' can not be used on type 'PlayerDetailsView' On 13.4 Please do check this out
Brian Voong
3 years ago
Ally Makongo
3 years ago
HELP & SUPPORT