han
han

Reputation: 551

CALayer and view controller views overlap intermittent problems

I have a main window controller which is a NSWindowController (golden rectangle) with a scrollview(blue rectangle), as well as a subview controlled by a NSViewController (yellow rectangle).

Depending on user selection, the respective nib file will be loaded into the subview via the NSViewController.

Unfortunately due to design limitations, the scroll view will be hidden or unhidden according to the user actions. This scroll view unfortunately has to overlap the view.

One of the views is also a qtmovielayer, so I have layer backed the main window controller and all the elements. Layer backing managed to get the scrollview to appear in front of the qtmovielayer.

When it all works great, it looks like the image on the left. however, 1/5 times when I start the app, the scroll view appears behind the subview as shown on the right. I've been trying and searching for about a week and a half now as to why this is happening, and I'm going bald from tearing and pulling at my hair.

The only resources that I could find on the net is setting the layer z position, but the problem still persists.

If anyone has any idea on why this is happening or how to solve this will be greatly appreciated. alt text

Upvotes: 0

Views: 484

Answers (1)

PapaSmurf
PapaSmurf

Reputation: 2475

You want to make the scrollview (blue) a subview of the subview (yellow). Subviews always appear 'in front' of their parent view. Like a family photo, the children always stand in front of the parents :) So, use the addSubView method in your viewDidLoad by sending the golden view the message to addSubview, and not just add the blue your main view.

Upvotes: 1

Related Questions