A part of my tvOS App UI is a minimized (400px width) AVPlayer
and a button that sets that resizes the AVPlayer
to fullscreen view by setting its frame to the window boundaries:
playerController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
.
I was not able to add a 'close fullscreen' button to the fullscreen avplayer (that would be the best solution) that's why I'm overriding the pressesBegan()
-method with:
override func pressesBegan(presses: Set<UIPress>, withEvent event: UIPressesEvent?)
{
guard presses.first?.type == UIPressType.Menu else
{
super.pressesBegan(presses, withEvent: event)
return
}
// If not minimized, minimize it
if playerController.view.frame.size.width != 400
{
playerController.view.frame = minimizedVideoBounds
}
}
The question
Is this a possible, safe and clean why to achieve my UX goal or is a a dirty hack that should be avoided at all costs?
In short: No it's not. I got weird side effects. I think we should use the AVPlayer
or the AVPlayerController
as full screen element and we should avoid subclassing this stuff.
If somebody is smart enough to handle this: Please tell me how.