I have a parent UIView
with several subviews.
The subviews are siblings - the child-views are not sub views of each other. (Each at the same heirarchical level in their superview)
For instance:
UIView *containerView = [[UIView alloc] initWithFrame:frame];
CustomUIView *childView = [[UIView alloc] initWithFrame:anotherFrame];
CustomUIView *yetAnotherChildView = [[UIView alloc] initWithFrame:anotherFrame];
[containerView addSubview:childView];
[containerView addSubview:yetAnotherChildView];
[containerView bringSubviewToFront:childView];
I want yetAnotherChildView
to be able to detect it was moved back in the view heirarchy. How can this be done?
Edit:
I understand that the containerView
can know what subviews are above what - but I don't wan't (can't) the containerView
notify its subviews that their order changed - Imagine adding a subview ontop of a stock view - the stock view has no idea of its subviews and that they would like to receive such a notification.
The subview CustomUIView
would need to observe some change in its superview
for instance (this probably is a very bad solution)
CustomUIView
-(id)initWithFrame
{
[self.superView addObserver:self forKeyPath:@"subViews" options:options context:context];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
// if keyPath is "subViews" array check if "this" view is ontop and adjust self accordingly
}