iOS改變控制元件圖層疊放順序
阿新 • • 發佈:2019-02-11
一般做圖類的APP對於控制元件圖層順序,疊放順序有一定的要求,下面是常用的幾個方法彙總:
- (void)removeFromSuperview;
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;
- (void)addSubview:(UIView *)view;
- (void)insertSubview:(UIView *)view belowSubview:(
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
- (void)bringSubviewToFront:(UIView *)view;
- (void)sendSubviewToBack:(UIView *)view;
- (void)didAddSubview:(UIView *)subview;
- (void)willRemoveSubview:(UIView *)subview;
- (void)willMoveToSuperview:(
- (void)didMoveToSuperview;
- (void)willMoveToWindow:(nullableUIWindow *)newWindow;
- (void)didMoveToWindow;
通過上面幾個方法可以簡單看出來,這些方法並不難,只是個別的不常用而已,改變控制元件疊放順序本質就是改變下控制元件的層次順序,就像PS中的改變圖層之間的上下順序一樣,理解本質了就很簡單了