view的superview的变换

今天遇到一个奇怪的问题,一个view(称为subview)被加在了一个cell(superView1)上,然后创建了一个view(为superView2),将subview重新加在了superView2居然没报错,在Cocos2dx里面这样是不允许的,一个控件只允许有一个父视图,可是当superView2添加了subview之后到底发生了什么,实际上在IOS中若subview被多次添加到不同的视图中,其父视图是最后一次添加的。。。。

例:

    UIView *childView = [[UIView alloc] init];

        UIView *superView1 = [[UIView alloc] init];

        [superView1 addSubview:childView];

        UIView *superView2 = [[UIView alloc] init];

        [superView2 addSubview:childView];

        UIView *superView3 = [[UIView alloc] init];

        [superView3 addSubview:childView];

        UIView *superView4 = [[UIView alloc] init];

        [superView4 addSubview:childView];

        此时childView的父视图superView为superView4

原文地址:https://www.cnblogs.com/chenhaosuibi/p/5068617.html