23

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!

4

3 回答 3

17

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.

于 2009-05-21T07:20:56.600 回答
1

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.

于 2011-12-08T06:25:54.963 回答
0

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.

于 2009-05-20T22:29:47.363 回答