Music application that uses iTunes Search API. Almost like Apple Music. Made with Clean Swift(VIP) architecture.
Stack: iTunes Search API, UIKit, SwiftUI, AVKit, URLImage, SDWebImage, Clean Swift(VIP).
override func viewDidLoad() {
super.viewDidLoad()
searchVC.tabBardelegate = self
var library = Library()
library.tabBarDelegate = self
let hostVC = UIHostingController(rootView: library)
hostVC.tabBarItem.image = #imageLiteral(resourceName: "library")
hostVC.tabBarItem.title = "Library"
viewControllers = [
hostVC,
generateViewController(rootViewController: searchVC, image: "magnifyingglass", title: "Search")
]
}
There are two main screens: Search
and Library
. Search screen made with UIKit
, and Library made with SwiftUI
. To make work them together in func viewDidLoad()
of MainTabBarController
(which is main controller for both views) I used UIHostingController()
.
var library = Library()
library.tabBarDelegate = self
let hostVC = UIHostingController(rootView: library)
Track player made with AVKit
let player: AVPlayer = {
let avPlayer = AVPlayer()
avPlayer.automaticallyWaitsToMinimizeStalling = false
return avPlayer
}()
func awakeFromNib()
anstead of func viewDidLoad()
, because TrackDetailView
representation made with xib file.
override func awakeFromNib() {
super.awakeFromNib()
}
private func setupGestures() {
miniTrackView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleTapMaximized)))
miniTrackView.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handlePan)))
addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handleDismissalPan)))
}
If you press play or pause you'll see that track image changes size with animation.
private func enlargeTrackImageView() {
UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
self.trackImageView.transform = .identity
}, completion: nil)
}
private func reduceTrackImageView() {
UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
let scale: CGFloat = 0.8
self.trackImageView.transform = CGAffineTransform(scaleX: scale, y: scale)
}, completion: nil)
}
SDWebImage provides an async image downloader with cache support.
miniTrackImageView.sd_setImage(with: url, completed: nil)
trackImageView.sd_setImage(with: url, completed: nil)