Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending view to back

Tags:

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!

like image 516
Hans Espen Avatar asked May 20 '09 19:05

Hans Espen


1 Answers

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.

like image 154
Rog Avatar answered Oct 03 '22 07:10

Rog