Rectangle 27 0

ios How to check if view, not viewController, is visible or not?


A UIView also has a hidden property which you can check as well as an alpha property which would make the view invisible if it was set to 0.

A UIView has a superview property and a window property. You can check to see if those are nil. If the view has a nil superview, then it has not been added to anything and is not visible.

If the view does have a superview property that is not nil then you can look at the subviews array property of the superview to determine the stack of views (0 is at the back).

If your view is not at the front of the stack, you would need to look at the frame rects of the other views in front of it to determine if they are covering it. Personally, I would use the CGRectIntersection command to test.

in my case, CGRectIntersection seems a good idea.

Note
Rectangle 27 0

ios How to check if view, not viewController, is visible or not?


UIView* view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
NSLog(@"%d", [[self.view subviews] indexOfObject:view1]); // Is 1

You can use this code get the index of the view and decide that it is in front or not

Note