Reputation: 355
I would be grateful if anyone could tell me how can I find out that one of my subviews is overlapped by anything (I mean some alerts or something like that)
Upvotes: 0
Views: 191
Reputation: 858
Use following code..
- (void)checkAnyViewOverlappingViewFrame:(UIView*)view topLevelView:(UIView *)toplevelview viewToSearch:(UIView*)viewtosearch {
// Get the subviews of the view
NSArray *subviews = [viewtosearch subviews];
// Return if there are no subviews
if ([subviews count] == 0) return; // COUNT CHECK LINE
for (UIView *subview in subviews) {
CGRect frameRelativeToParent = [subview convertRect:subview.bounds
toView:toplevelview];
if (CGRectIntersectsRect(view.frame, frameRelativeToParent) && view.layer.zPosition < subview.layer.zPosition) {
NSLog(@"Overlapping view: %@", subview);
}
[self checkAnyViewOverlappingViewFrame:view topLevelView:toplevelview viewToSearch:subview];
}
}
Here view
is your subviews to check. In toplevelview
pass self.view
which parent view of all views. In viewtosearch
pass self.view
Upvotes: 1
Reputation: 9356
you can view itself in xcode while running the app. Follow these steps.
Upvotes: 2