Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 14, 2013, 08:00 PM   #1
xArtx
macrumors 6502a
 
Join Date: Mar 2012
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];
Or should I create a duplicate of the back layer, put one in front,
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?
xArtx is offline   0 Reply With Quote
Old Jan 14, 2013, 08:02 PM   #2
ConCat
Banned
 
Join Date: Jul 2012
Location: In an ethereal plane of existence.
For optimal resource management, I would recommend only having visible views attached to any other view, and otherwise just sitting in a strong pointer.
ConCat is offline   0 Reply With Quote
Old Jan 14, 2013, 08:12 PM   #3
xArtx
Thread Starter
macrumors 6502a
 
Join Date: Mar 2012
Quote:
Originally Posted by ConCat View Post
For optimal resource management, I would recommend only having visible views attached to any other view, and otherwise just sitting in a strong pointer.
So the first way is fine if it's only being swapped while framerate doesn't matter?

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.
xArtx is offline   0 Reply With Quote
Old Jan 14, 2013, 08:22 PM   #4
ConCat
Banned
 
Join Date: Jul 2012
Location: In an ethereal plane of existence.
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.
ConCat is offline   0 Reply With Quote
Old Jan 14, 2013, 09:28 PM   #5
Punkjumper
macrumors newbie
 
Join Date: Jan 2013
Code:
insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;

bringSubviewToFront:(UIView *)view;
sendSubviewToBack:(UIView *)view;
Punkjumper is offline   1 Reply With Quote
Old Jan 14, 2013, 10:03 PM   #6
xArtx
Thread Starter
macrumors 6502a
 
Join Date: Mar 2012
Quote:
Originally Posted by Punkjumper View Post
Code:
insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;

bringSubviewToFront:(UIView *)view;
sendSubviewToBack:(UIView *)view;
Nice
Looks like two different ways, not just one lump of code.
xArtx is offline   0 Reply With Quote
Old Jan 15, 2013, 10:05 AM   #7
Punkjumper
macrumors newbie
 
Join Date: Jan 2013
Yes. Choose what one you want
Punkjumper is offline   0 Reply With Quote
Old Jan 15, 2013, 12:11 PM   #8
ctdonath
macrumors 65816
 
Join Date: Mar 2009
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.
ctdonath is offline   0 Reply With Quote
Old Jan 15, 2013, 05:25 PM   #9
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
Probably more like setNeedsDisplay, but maybe they do the same thing.
PhoneyDeveloper is offline   0 Reply With Quote
Old Jan 16, 2013, 06:21 AM   #10
KoolStar
macrumors Demi-God
 
KoolStar's Avatar
 
Join Date: Oct 2006
Location: Kentucky
Send a message via AIM to KoolStar Send a message via Skype™ to KoolStar
Quote:
Originally Posted by PhoneyDeveloper View Post
Probably more like setNeedsDisplay, but maybe they do the same thing.
If we look at what setNeedsLayout and setNeedsDisplay do we can see that setNeedsDisplay calls drawRect: at the end of the run loop. SetNeedsLayout do the same thing with layoutSubviews.

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.
__________________
"Innovation distinguishes between a leader and a follower." : S.J.
KoolStar is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Mavericks reordering desktop screens jca69 OS X Mavericks (10.9) 4 Dec 30, 2013 01:55 AM
Photoshop Layers geoffpalmeruk Digital Photography 2 Dec 13, 2013 07:57 AM
UITabBar setSelectionIndicatorImage doesn't work after tab reordering Tex-Twil iPhone/iPad Programming 2 Aug 4, 2012 02:52 AM
iOS 6 Beta Allows Reordering of Icons on Apple TV MacRumors iOS Blog Discussion 53 Aug 2, 2012 11:46 AM
Reordering rows in a view-based NSTableVIew monsieurpaul Mac Programming 2 Jul 19, 2012 08:21 AM

Forum Jump

All times are GMT -5. The time now is 08:58 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC