1

I have a UIView that adds a subview on top of it when plays videos, I now want to have elements on top of that Subview that displays a full name and a profile image. I am receiving the data but I think that the subview which displays the video hides the elements on top of it. This is my storyboard below, the black screen below is my UIView which the video is displayed on and I obviously have the full name, time and a UIImage element on top but can not see it. My constraints are good too. This is my code.

class BookViewC: UIViewController { 

 var timeLineModel = TimeLineModel()
 var streamsModel = streamModel()
    @IBOutlet weak var Profile_Image: UIImageView!
    @IBOutlet weak var VideoView: UIView!
    @IBOutlet weak var FullName: UIButton!
    @IBOutlet weak var Time: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
       FullName.setTitle("John Higgins", for: .normal)
       Time.text = "2:30 pm"
        PlayVideo(MediaHeight: 400.0, MediaURL: "URL")
        Profile_Image.layer.cornerRadius = Profile_Image.frame.height / 2
        Profile_Image.clipsToBounds = true     
    }

    func PlayVideo(MediaHeight: Float, MediaURL: String) {
        let movieURL = URL(string: MediaURL)
        streamsModel.playerView = AVPlayer(url: movieURL!)
        streamsModel.MyAVPlayer.player = streamsModel.playerView
        streamsModel.MyAVPlayer.videoGravity = AVLayerVideoGravity.resizeAspectFill.rawValue
        streamsModel.MyAVPlayer.showsPlaybackControls = false
        streamsModel.MyAVPlayer.view.frame = VideoView.bounds
        // If comment out the line below the elements show but not the video
        VideoView.addSubview(streamsModel.MyAVPlayer.view)
        self.addChildViewController(streamsModel.MyAVPlayer)
        streamsModel.playerView?.isMuted = false
        streamsModel.MyAVPlayer.player?.play()
    }

}

I believe the issue is with this line VideoView.addSubview(streamsModel.MyAVPlayer.view) if I comment out that line then the video does not show but you can hear it then the elements of full name, time and profile image are visible. Is it possible to add these elements on top of the SubView? since I have seen some other apps doing that?

enter image description here

JOM
  • 8,139
  • 6
  • 78
  • 111
user1591668
  • 2,591
  • 5
  • 41
  • 84
  • Have you tried reordering the elements in your xib? It could be that the video view sits above the other views. Try changing the zPosition to see if that’s it. – Mary Martinez Apr 15 '18 at 03:49
  • i think the Label, Button, Image are inside `VideoView`. And then you have added subview to the `VideoView`. So the newly added view will be on Top. – Lal Krishna Apr 15 '18 at 03:52
  • 1
    Try `VideoView.insertSubview(streamsModel.MyAVPlayer.view, at: 0)` – Lal Krishna Apr 15 '18 at 03:54
  • I can try reordering the elements in the xib file and yes they are inside the UIView VideoView and the subview is on top I’m just trying to figure out how I can get those elements to be on top of that subview too . – user1591668 Apr 15 '18 at 03:55
  • You can check here to set the order of views https://stackoverflow.com/questions/4631878/how-to-set-iphone-uiview-z-index – Kamran Apr 15 '18 at 04:38
  • @LalKrishna perfect that worked if you put this in a comment response I'll put it as the answer – user1591668 Apr 15 '18 at 21:38
  • Added the answer. Please check it, https://stackoverflow.com/a/49851201/4061501 – Lal Krishna Apr 17 '18 at 09:18

1 Answers1

1

i think the Label, Button, Image are inside VideoView. And then you have added subview to the VideoView. So the newly added view will be on Top.

Try

VideoView.insertSubview(streamsModel.MyAVPlayer.view, at: 0)
Lal Krishna
  • 15,485
  • 6
  • 64
  • 84