我有一个UIView
有几个子视图的父母。
子视图是兄弟 - 子视图不是彼此的子视图。(每个人都在他们的超级视图中处于相同的层次结构)
例如:
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];
我希望yetAnotherChildView
能够检测到它在视图层次结构中被移回。如何才能做到这一点?
编辑:
我知道containerView
可以知道哪些子视图高于什么-但我不想(不能)containerView
通知其子视图他们的订单已更改-想象在股票视图上添加子视图-股票视图不知道的子视图,并且他们希望收到这样的通知。
子视图CustomUIView
需要观察它的一些变化superview
例如(这可能是一个非常糟糕的解决方案)
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
}