Keep a static graphic always fixed on screen while changing uiviews in xcode - ios

Is there any way to have a static graphic on screen that doesn't move when pushing / popping view controllers?
The best way I can think to describe this is like a tab bar.
If you have a tab on a tab bar that has multiple pages that swipe left/right, you can view these different pages, and only the main content area moves, while the tab bar stays fixed and doesn't swipe in/out along with the content.
I want to do something similar with a custom toolbar I have created and added to a view, but just now it slides out with the previous viewcontroller and then slides in with the new view controller.
Is there any way to keep that fixed on the screen so that it doesn't move.
Hope that makes sense!

Yes, you can do this using container view.
It is fairly new to XCode, so it doesn't have the widespread use that navigation controllers and tab bars do, but it works similarly.
Basically, You will create a new UIViewController instance in storyboard, and put a Container View inside the view controller, filling the entire view controller. From there, you will right click on the view controller where your flow starts (probably either a tab bar controller or a navigation controller) select embed, and target the container view in your new view controller. Finally, you'll need to change the initial view controller (the arrow that points to the first view controller the app should load) to this new UIViewController that has your container view.
If you run your app at this point, you should notice no difference at all. The entire app is basically running inside the container view of that new view controller. Now, you can a UIImageView to that new view controller anywhere you want. Since the new view controller doesn't ever go away, the UIImageView you put inside it will stay there no matter what the container view is showing.
Hope this helps!
Note: I should add that if your program uses any modal transitions, that will cause the flow to exit the new view controller and it's container view as well, similar to how this affects tab bar controllers.

Related

How to fix incorrect (small) view on my main storyboard

So In my main storyboard one of my view controllers view is smaller than it should be, making that part of the UIView untouchable to the users... I don't know if its a tool bar or some weird inherited view from the previous view controller as it does have a relationship to the previous view controller
tried removing tool bar, I even put my tableview over top of the view making it bigger, but it is unusable on the iPhone after the build
I just need it removed, its a grey bar
I am going to assume that gray is being passed over to your present view controller, I would remove the segue to check if the view updates its constraints, if so remove the previous view controller and embed it to the previous to remove the bar

iOS Swift How to go back from a split view to a normall view controller

I have a simple iOS app that I want to use a split view in, but I also need some normal view controllers(non Split view). So I have my story board setup like this:
Story board
I will add more views to the base navigation view depending on what they click on in the first view some will go to other standard views and one will go to another split view. as I can not add the split view to my base navigation view (get an error saying it had to be the root view) I replace the root view with the split when the button is clicked using a replace Segue.
My question is: how do I get back to the first view once I am in the splitview? can I somehow had a custom back button to the detail view title bar to go back? Or am I going about the whole thing wrong? Any help or a push in the right direction would be great!
I ran into this problem myself. Unfortunately, UISplitViewController cannot be added as a child of another view controller. I must be the root view controller of a window. From the docs: When building your app’s user interface, the split view controller is typically the root view controller of your app’s window. The way I got around this was just creating a container view controller in my storyboard: It ended up looking like this:
It's pretty basic, just adding the two view controllers as children of the parent view controller. You can control the width of each on straight in IB.

iOS custom view across all view controllers

I would like to have custom view set in one screen and have it across all view controllers in my application.
I find solution with using Container view. So I create RootViewController and I give it Container view and set my original MainViewController as embed in container. I added view to RootViewController and in first view controller (MainViewController) it looks good.
The problem is when I go to another view controller by Push segue. New view controllers covers whole screen (which is okay) and covers custom view too. I was thinking that it could help if I add Navigation Controller with root MainViewController and this navigation controller would be embed in RootViewController but the result is same. I set Navigation bar as hidden (same for status bar) because I want to be hidden.
So where could be problem? Or how would you add custom view to all screens? This custom view should work as global (I am using NSTimer and counting time) so I solution with inheritance isn't for me.
You can use application window and add this custom view as subview whenever required. I have used it in one of my app to show notifications (if there area any) and it works great.
Get handle to Application Window and add subview to it. Custom view can be created from a singleton class or App delegate.
You could try it the other way round. Make a view which will never change inside your root view controller and a container view and just change the content of the container view depending what u want to display next to your unchanging view.

Partial segue to show settings view

in the google maps app for ios. When you select the settings button, it will show you a view of options such as "traffic", "public transit", etc.
My question is how this is done on ios.
I tried following this tutorial but it says that it won't work on uinavigationviewcrollers. I have seen this partial segue of the the view in apps that use a navigational controller. How do they create that?
It's not a partial segue. It's not a segue at all, it use of containment view controllers.
Instead of a single view controller which transitions to a different view controller image one single master view controller. For simplicity, we'll say this view controller has two views (of the root), both of which cover the the whole screen. For this example let's think of them as "main" view and "menu" view.
Other than these two empty views, the view controller has no content. That's because this view controller does nothing other than manage other view controllers which get stuck into the two views. It will have a couple methods manage them, like presentInMainView:(UIViewController *)viewcontroller and presentInMenuView:(UIViewController *)viewcontroller
When the program starts running the master view controller will programmatically add the map to it's "main" view. The map view controller now cover the whole screen and looks and acts like it's the top level view controller, but it isn't. It's contained. At some point some taps the settings button and the map view controller will make a call to it's parent and say presentInMenuView:... and the master view controller will then load up a second view controller into the menu view. The menu view could even be located off the left side of the screen and the master view controller animates the menu view frame to side it right covering the whole screen. Assuming the menu view controller only has content which covers the left half of the screen you'll see the map view controller hiding behind it.
That really only scratches the surface, lots can be done with container view controllers. You could create a container which lets you brings up a dozen different views all populated with view different view controllers. You could size and arrange them on all over the screen and each child view controller could still only have to deal with it's own contents.
For more info there is the Apple Developer Guide and the WWDC 2011 Videos where it was introduced (session 102)
I used SWRevealViewController For similar type of sidebar animation.They given the good example of how to use SWRevealViewController also please try it once.

How to make slide menu static or re-useable iOS?

I am trying to make the slide menu re-useable without having to constantly add the same menu to every viewController in the menu drawer. How can I re-use, can I wrap all my view controllers within some type of main controller?
You could create a new root view controller which contains the slide menu and also contains a container view that covers the entire size of the screen.
Within the container view you would embed your old root view controller.
The slide menu is now available to every view controller in your application and you can make it appear or disappear when you want by animating its frame origin to slide onto and off of the screen.
You could use AMSlideOutNavigation
https://github.com/andreamazz/SlideOutNavigation

Resources