How can I find out ahead of (apparently) a UIView?

I need to determine which front view (currently visible). How can i do this?

Here is what I would like to do:

if ( ! <<methodToTellIfViewAIsInFront>>) { [viewA prepareToDisplay]; [window bringSubviewToFront: viewA]; } 
+6
iphone uiview
source share
6 answers

UIView does not necessarily have the concept of being ahead. UIWindows may or may not be key, but it's not exactly the same.

You can bring a view to the forefront, but that does not mean that it is either not visible. Remember that submissions can be of any size.

A UIView deeply immersed in a hierarchy may be partially visible, it may be obscured, or it may be behind some translucent appearance. Similarly, the front view cannot be seen at all if its opacity value or hidden flags are changed.

I think you want to check the subviews NSArray of your supervisor or UIWindow and check this out. I cannot remember what a front is, but it is either the first or the last object.

Eyeliners are drawn using the painting method. Representations are drawn in order from far to nearest, and the last object drawn is “in front”.

+13
source share

Add this to view the controller:

  - (void) viewDidAppear: (BOOL) animated {
  [super viewDidAppear: animated];
  visible = YES;
 }

 - (void) viewWillDisappear: (BOOL) animated {
  visible = NO;
  [super viewWillDisappear: animated];
 }

and check the 'visible' ivar

+3
source share

YES will be returned next if viewA is in front:

 [[viewA.superview.subviews lastObject] isEqual: viewA] 
+3
source share

Check that [UIView.window isKeyWindow] == YES

+2
source share

The only way to do this is to assign a unique identifier to your view using the [UIView tag], and then use the [UIView viewWithTag] to bring it to the front.

Or you can search for the view you need using the tag and work on it.

 for (UIView *checkView in [self.view subviews] ) { if ([checkView tag] == whatever) { // Do Whatever you need to do } } 

.. then bring him to the front.

Greetings

0
source share

When working with modal views, this code worked with me in my root view controller:

  if(self.view == [(MyAppDelegate *)[[UIApplication sharedApplication] delegate].window.subviews objectAtIndex:0]){ ... // stuff here } 
-one
source share

All Articles