|
|
#1 |
|
Reordering UIImageView layers
Hi Guys,
I have some situations where I want a UIImageView that is normally in the background, to become the front layer (it has a lot of transparent area). Is the best way to remove the view and then add it again in the right order? Code:
[backImageView removeFromSuperview]; // remove and add again to bring background to the front
[frontImageView removeFromSuperview];
[self.view addSubview:frontImageView];
[self.view addSubview:backImageView];
and one at the back at all times, and keep one or the other clear? I guess the question I'm asking is about the overhead for iOS in going one way or the other. Some part of iOS must have to draw this extra blank layer to the screen, even if we don't have to do it manually right? |
|
|
|
0
|
|
|
#2 |
|
For optimal resource management, I would recommend only having visible views attached to any other view, and otherwise just sitting in a strong pointer.
__________________
Con + Cat |
|
|
|
0
|
|
|
#3 | |
|
Quote:
When the background is in front, the foreground layer is still visible thanks to transparency. Think a row of hills as the background, but you might want it to be a foreground if the objects on the other layer are going to appear to be behind the hills. |
||
|
|
0
|
|
|
#4 |
|
Ah, okay, I get what you're saying. I don't have much experience with that specific scenario. I was just commenting on something I knew.
You might want to try stackoverflow.com though. You're almost guaranteed to get your questions answered there, assuming the question isn't too complex, which this isn't, I just don't personally know.
__________________
Con + Cat |
|
|
|
0
|
|
|
#5 |
|
Code:
insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview; insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview; bringSubviewToFront:(UIView *)view; sendSubviewToBack:(UIView *)view; |
|
|
|
1
|
|
|
#6 | |
|
Quote:
![]() Looks like two different ways, not just one lump of code. |
||
|
|
0
|
|
|
#7 |
|
Yes. Choose what one you want
|
|
|
|
0
|
|
|
#8 |
|
Related question: how to prompt re-running of loadView: ? i.e.: having changed order/content of self.view, need to regenerate what's displayed.
ETA: Ah, it's [self.view setNeedsLayout]; Last edited by ctdonath; Jan 15, 2013 at 02:04 PM. |
|
|
|
0
|
|
|
#9 |
|
Probably more like setNeedsDisplay, but maybe they do the same thing.
|
|
|
|
0
|
|
|
#10 | |
|
Quote:
Also setNeedsLayout will only have an effect if your subclass overrides layoutSubviews method. In most cases setNeedsDisplay should be sufficient to repaint a view. That may help some people out when they go to use either method call.
__________________
2.4 MacBook Aluminum 480GB SSD/750GB Optibay 8GB RAM CE | MacBook 2.4 SR 4GB, 320GB HD | PB G4 1.67 | 15 TiBook-DVI 800 iPhone 4S 16GB | iPhone 5 32GB
|
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 03:53 AM.









Linear Mode
