开发者

Attach a UIView to a UIViewController programmatically?

What is the best way of having a block of screen run by it's own view controller, whilst the rest of the app runs as normal, switching between views etc.

So the block of screen would be a permanent fixture (tho could be hidden), while the user can switch between tab, push new views etc?

Is there a way to programmatically attach a view to a view controller to do this, or is there some other method?

-----------------------------------------
|                                       |
|           nav bar or tool bar         |
-----------------------------------------
|                                       |
|                                     开发者_如何学Go  |
-----------------------------------------
|view to be attached to view controller | < this block stays even when in other views
-----------------------------------------
|                                       |
|                                       |
|                                       |
|           main bit of the view        |
|          changes according to tab     |
|                                       |
|                                       |
|                                       |
-----------------------------------------
|       |       |       |       |       |
|       |       |       |       |       | < tab bar
|       |       |       |       |       |
-----------------------------------------


Instead of attaching to view controller, create the view in appDelegate or a singleton instance of the view and whenever a new view is pushed/switched, this view is moved to the front by writing

[self.view addSubview:_yourStaticView];

in the view did load methods of each view controller class. A single UIView controller has a stack, so it cannot render multiple views at the same time, it's either one or the other. Whenever you want to remove this view, write:

[_yourStaticView removeFromSuperview];

You can change the contents of this view just as you would with a UIView!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜