Hans Espen
Hans Espen

Reputation: 1127

Sending view to back

When I try to send a view to the back, it hides some of the buttons and labels in my view controller. The view I am sending to the back is a UIImageView. Does anyone have an opinion of what might be the problem?


Here is the code I am using:

UIImage *image = [UIImage imageNamed: @"background.jpg"];
UIImageView *backImage = [[UIImageView alloc] initWithImage: image];
[self.view addSubview: backImage];
[self.view sendSubviewToBack: backImage];

Then, when I am adding controls to self.view, they does not always show


I managed to get it roght by moving my code from init to loadView. I don't understand why that should make a difference, but hey.. it works!

Upvotes: 23

Views: 24456

Answers (3)

Rog
Rog

Reputation: 17170

If you are using UIView's sendSubviewToBack: or a similar message, you probably have your buttons inserted in the hierarchy under the UIImageView. When a view moves in the hierarchy, all of its subviews move with it.

To fix this, you need to add your controls as subviews of the same view (possibly the UIWindow) you added the UIImageView to initially.

Without seeing your code, it's very difficult to be more precise.

Upvotes: 17

Jeanine Jue
Jeanine Jue

Reputation: 81

By not having to add it programmatically and adjust the views, much easier to layer each one in the interface builder. Make sure the image view, if this is set as the background, make sure it is the first to be listed.

Upvotes: 1

mmc
mmc

Reputation: 17414

Agreed. Not quite sure by what you mean by "send to the back" but here's a guess...

If you are adjusting the layering within your main view, be sure you are not sending a view "to the back" (changing it's layer) that has number of subviews... or else they would all go to the back (their layering would change) at the same time.

If this is totally not what you meant, just let me know, and I'll delete this answer.

Upvotes: 0

Related Questions