0

I'm currently working on a game. It plays a movie and the story changes depending on the players actions. I'm using quick time events (press a button in x seconds). When there's a quick time event I want to show the button that has to be pressed and the time left to press that button.

I play the movie(s) using an AVPlayerView. On top of that AVPlayerView I have placed a label. But the label is always invisible. It's because of the AVPlayerView.

So does anyone know a way around this?

Edit

I didn't use any code to place the label on top of the AVPlayerView. I just placed it there in the MainMenu.xib. When I view it in Xcode it looks like this:

Screenshot in Xcode

But when I run the application it looks like this:

Screenshot in Xcode

As you can see in the first image, all objects are under "View" and the label appears lower in the list so it should be on top of the AVPlayerView. Xcode displays the label on top of the AVPlayerView (image 1), but when I run the application the label is underneath the AVPlayerView (image 2). So my question was how to display the label on top of the AVPlayerView.

I hope this is enough information ;)

Developer
  • 406
  • 1
  • 4
  • 18
  • Question: How do you put the label on top of the view? Suggestion: Try using Xcode's view capture feature to examine the position, size, and z-order of your views while the application is running. – Phillip Mills Dec 12 '17 at 16:26
  • @PhillipMills I can't see the label there – Developer Dec 12 '17 at 16:40
  • Well, that leads back to my question then. – Phillip Mills Dec 12 '17 at 16:45
  • @PhilipMills How I put in on top of the view? I just dragged a label onto the view in the MainMenu.xib. I can see the label in Xcode but not in the application. – Developer Dec 12 '17 at 16:47
  • 1
    Have you switched the player and label to beibg layer-backed? – uliwitness Dec 12 '17 at 18:46
  • "On top of that AVPlayerView I have placed a label. But the label is always invisible." Nobody but you sees it since you don't even show a single line of code. – El Tomato Dec 12 '17 at 22:39
  • 1
    If u drag the label onto the view, the label will be a child of the view. hence your layer will cover up the label. what you need to do is put the label above the view. – GeneCode Dec 13 '17 at 01:25
  • @ElTomato I didn't use any code. That's why I didn't even show a single line of code. I have added screenshots to show the problem. – Developer Dec 14 '17 at 16:54
  • 1
    try superView.bringSubviewToFron(subview) – scord Dec 14 '17 at 16:54
  • @scord It says "Property 'bringSubviewToFront' not found on object of type 'NSView *' " – Developer Dec 14 '17 at 17:12
  • 2
    I just tried this: new Cocoa project (non-storyboard); drag a AVPlayerView onto the default window. Drag a Label onto the default window, increase font size and colour red, partially overlap the player view. The label renders on top of the player in both Xcode and the debugged application. So there seems to be something else at play here. Did you try this simple test in a new, blank Cocoa application to try and isolate the issue? – TheNextman Jan 03 '18 at 18:31
  • @TheNextman That did work actually. But I didn't do anything different this time. I only made a new project. I'm sure this is a clue, but I don't know what's causing this. – Developer Jan 03 '18 at 21:26
  • @Developer There must be a difference :) If you find it, you answer your question.. – TheNextman Jan 04 '18 at 19:24

1 Answers1

0

Link your label to an IBOutlet in the ViewController which describes your view and in the viewDidLoad() method write

/*top of your file*/
@property (strong, nonatomic) IBOutlet UILabel *myLabel;
/* other properties */

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    /*code*/

    [self.view bringSubviewToFront:myLabel]; 
}

/*rest of your code*/

This should do the trick for you.