ios - Hide controls in AVPlayerViewController -- only at start -
if set avplayerviewcontroller.showsplaybackcontrols false, controls not show @ all. if tap screen.
i want controls start out hidden, still able summon them tapping. if set mentioned property true, start out visible. (yes fade after few seconds.) there way start hidden, still accessible?
update: ended making own controls better customization. it's more difficult worth time. please read apple's sample code reference. it's implementing pip making custom controls: https://developer.apple.com/library/prerelease/ios/samplecode/avfoundationpipplayer/introduction/intro.html
update: when tapped, avplayerviewcontroller fires touchesbegan event, , not touchesended event. it's enough show controls.
first need hide control. put code right before present avplayerviewcontroller
youravplayerviewcontroller.showsplaybackcontrols = false
then subclass avplayerviewcontroller , add function:
override func touchesbegan(touches: set<uitouch>, withevent event: uievent?) { self.showsplaybackcontrols = true super.touchesbegan(touches, withevent: event) }
old sollution:
i've solved this. main idea put uiview on top of avplayerviewcontroller reveive tap gesture, , hide uiview when no longer needed.
here's code:
import avkit import uikit // create custom avplayerviewcontroller @available(ios 8.0, *) final class customavplayerviewcontroller: avplayerviewcontroller { // create uiview put on top of lazy var topview = uiview(frame: cgrectmake(0, 0, width, height)) override func viewdidload() { super.viewdidload() // sure, set clearcolor // (don't set alpha = 0 because stop receiving user interaction) topview.backgroundcolor = uicolor.clearcolor() // add view of avplayerviewcontroller self.view.addsubview(topview) // bring front self.view.bringsubviewtofront(topview) // add tap gesture recognizer topview.addgesturerecognizer(uitapgesturerecognizer(target: self, action: "handletap")) } // handle tap func handletap() { // show control self.showsplaybackcontrols = true // hide topview. can unhide when needed later. self.topview.hidden = true } }
and when need hide controls, this:
var avviewcontroller = customavplayerviewcontroller() ... // hide controls avviewcontroller.showsplaybackcontrols = false // show topview avviewcontroller.topview.hidden = false
Comments
Post a Comment