Difference between addSubview and insertSubview in UIView class

后端 未结 4 653
情书的邮戳
情书的邮戳 2020-12-02 11:16

What is the difference between addSubview and insertSubView methods when a view is added programmatically?

4条回答
  •  一整个雨季
    2020-12-02 11:35

    1.addSubview add subview in array then add in View'slayer

    - (void)addSubview:(UIView *)subview
    {
        [_subviews addObject:subview];
        [_layer addSublayer:subview.layer];
    }
    

    }

    2.While insertSubview add your view as subview then call [_layer insertSublayer:subview.layer atIndex:index];

    - (void)insertSubview:(UIView *)subview atIndex:(NSInteger)index
    {
      [self addSubview:subview];
      [_layer insertSublayer:subview.layer atIndex:index];
    }
    

提交回复
热议问题