How to organize Controllers and Views (iOS) - ios

I want my UITabBarController to be with frame (0;100;320;380).
In addition to UITabBarController I want to have a view with frame (0;0;320;100).
This view is supposed to be independent from TabBarController and always visible. When different Tabs are opened top view should remain visible, like UINavigationBar.
Is there any way to do it?

Create a UIViewController subclass, in the xib add two views, one upperview and another lowerview with the sizes you want
In the view did load of this view controller, create a UITabBarController, and add to it the view controllers you wish
then do
[lowerview addSubView:tabBarController.view];
[upperview addSubView:yourUpperView];

Related

Is it possible to use a single UIView across multiple UIViewControllers?

I have 6 UIViewControllers in my app at the moment, and while they are all different, they should all share the same custom toolbar at the top, as well as a drawer which is opened/closed by a button on said toolbar. The "toolbar" and "drawer" are both UIViews with some stuff inside. Is it possible to use the same UIView objects for all 6 of my UIViewControllers? Or do I have to copy the constraints, segues, controller code, etc for the toolbar and drawer for each UIViewController that I have in my app?
Take a look at containerView.
You can add containerViews in each of your ViewControllers and embed your UIView.
What you could do in this situation is make a view controller that embeds a child view controller. On this view controller, you would set up your toolbar and drawer, then you would have a Container View that can embed a navigation controller which would manage all your other view controllers. On a storyboard, you can right-click and drag from a Container View to another controller to embed it.

Can I use storyboard to embed UINavigationController's view inside a UIViewController?

I want to keep the top and bottom sections of my view stationary and I only want to add a navigation controller at the center of the screen.
This has been perfectly doable for a lot of years and now as everyone is so enchanted by the Storyboards, I wanted to do the same through the storyboard and it seems like it is impossible.
Is it possible anyways?
you can use Container View in the storyboard.
Container View defines a region within a view controller's view
subgraph that can include a child view controller. Create an embed
segue from the container view to the child view controller in the
storyboard.

Sharing a common background image in a UINavigationController hierarchy?

I know it's possible to set a background image for the UINavigationBar, but I would like to know if there is a way to share a common background view for all controllers in a UINavigationController. The idea is to have a UIImageView as the background that stays in place rather than "sliding" over itself when navigating to a new controller.
A navigation controller is a kind of view controller and it hosts the currently visible view controller by adding the VC view to its view. You can add things to that view too. Create your image view and add it as a subview of the nav controller view, then send it to the back (or insert at index 0).

Using iOS 6 autolayout, what would be the proper way to display somthing above an UINavigationController?

In my app, i have a main view controller which sometimes brings a modal view on top of it. This modal view is a UINavigationController with a navigation bar. I want to display an image above the navigation bar, and have the navigation bar appear below the image.
I do not want to subclass anything and the app uses autolayout, i do not want a bunch of delegate callbacks and frame calculations. The view inside the navigation controller (the actual modal content) must still respond to different screen sizes correctly, such as rotation, call status bar etc. Also, no IB solutions please, these views are all managed in code.
How do i accomplish this?
I would turn off AutoLayout and place the image at the top
I don't think you can do it with your modal view being a navigation controller. I would do it by making that modal controller a UIViewController that you set up as a custom container controller. You can add an image view to the top of this controller's view and add the view of a child view controller (which would be a navigation controller) to the bottom. This would be a lot easier to do in a storyboard using container views, but it certainly can be done in code.

Segue from a scrollview

I have a UIscrollview that takes up about half of a screen. The scrollview contains a series of view controllers that have buttons that have segues to another view controller. When that segue is followed, it loads the view controller on top of the current scrollview.
I want that new view controller to act like any other modal segue would act if the button was not within a subview or scrollview. In other words, take up the whole screen.
Can you use segues from within a subview or a scrollview?
Thanks!
The scrollview contains a series of view controllers that have buttons
that have segues to another view controller.
An instance of UIScrollView can't "contain" view controllers -- it can only contain other views. It might contain views that are managed by other view controllers, but if you're using many view controllers all at the same time you may want to read Am I abusing UIViewController Subclassing?.
I ended up just using delegates and protocols between the views in the scrollview and the parent view controller and then I launch the new view from the parent view controller. Seems to be doing the trick.

Resources