I have a video player view controller (I’m gonna call it PlayerVC
) that consists of an AVPlayer
and a custom timeline view. In one of my features I can add 2 PlayerVC
s to a super view controller as their child view controllers.
It looks like this:
I have a feature where I can have 2 separate PlayerVC
s and play both videos using a single timeline. What I do is this:
// In my Parent View Controller
func addSecondPlayer() {
let playerVC = PlayerVC()
addChild(playerVC)
playerVC.didMove(toParent: self)
// Setting some constraints below...
}
// Stretching my timeline
func stretchTimelineConstraint(_ stretch: Bool) {
guard let parent else { return }
NSLayoutConstraint.deactivate([timelineContainerViewLeadingConstraint])
if stretch {
timelineContainerViewLeadingConstraint = timelineContainerView.leadingAnchor.constraint(equalTo: parent.view.leadingAnchor)
} else {
timelineContainerViewLeadingConstraint = timelineContainerView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor)
}
NSLayoutConstraint.activate([timelineContainerViewLeadingConstraint])
}
So it will look pretty much like this:
Here I used the timeline of the right PlayerVC
so I set the leading constraint to match the Parent View Controller to stretch the timeline to the whole width of the Parent View Controller. But now I can’t scroll the timeline outside the it’s PlayerVC
‘s bounds (which is one on the right). Is there anyway to solve this? FYI, I’m using this library for the timeline view.