简体   繁体   中英

UIView hierarchy

I am just curious if I have a webview, and I want to have another custom uiview set on top of it.

So basically I have a window, and I have two views:

|--View1--| |--webView|

how can I set these views based on the window on hierarchy manner? So one view and lay on top of another view?

Thanks

You can just add the uiview on top of the webview. Just set the frame for the otherview, and then add it.

otherView.frame = CGRectMake(0, 430, webView.frame.size.width, 50);
[webview addSubview:otherview];

UIView类的subviews文档中:“数组中的子视图的顺序反映了它们在屏幕上的可见顺序,索引为0的视图是最后一个视图。”

You can change the order of currently added UIViews, there are some methods that you can use to control the hierarchy programatically, like that:

  • addSubview:
  • bringSubviewToFront:
  • sendSubviewToBack:
  • removeFromSuperview
  • insertSubview:atIndex:
  • insertSubview:aboveSubview:
  • insertSubview:belowSubview:
  • exchangeSubviewAtIndex:withSubviewAtIndex:
  • isDescendantOfView:

Put special attention on the methods in bold, seems that is exactly what are you looking for. Also look around apple UIView documentation here .

See ya!.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM