I want to create an ios app in which I want to flip uiviewcontrollers. I want to use swipe gesture to change between uiviewcontrollers.
I have 2 uiviewcontrollers, in which I want to set one view controller to the top of uiviewcontroller cover and one view controller to the bottom ,and then make an animation that let a top uiviewcontroller slide to left to out of screen and the bottom uiviewcontroller will appear step by step.
What is the Best way to do this ?
Create a RootViewController with container views.
Add the child view controllers to the root view controller.
Add gesture recognizers to manipulate the views.
Use the "view controller containement" a feature of iOS5, to make managing the lifecycle calls easier.
As Jasper wrote you should create new UIViewController - "root" which will hold the child UIViewControllers- "bottom" and "top". It will also display their views. To achieve an effect that "bottom" is underneath, you should add its view as a subview first.
Take a look at http://developer.apple.com/library/ios/#samplecode/PageControl/Introduction/Intro.html It might give you an idea how to handle with child UIViewControllers
Related
I want to put two UIViewController in one screen simultaneously in UIKit. However, I couldn't find the solution.
Like this:
I want to display both UINavigationController and Admob Banner in one screen and independently. The one doesn't affect the other.
Could you tell me how to do this?
You want to use view controller containement. The easiest way to do this is as follows.
Open your storyboard.
Add a view controller. Let's call it "Parent". Give it a unique identifier.
Tap the "+" to add a new component to your parent view controller. Search on "Container" and drag 2 container views onto your parent view controller. Those container views will contain the content view of your 2 view controllers. Set up the constraints on those container views so they are laid out top and bottom as you show in your picture.
Next add view controllers for view controller 1 and view controller 2 to your storyboard. (you can also add links to view controllers from other storyboards, but I'll ignore that.) Lets call those Child1 and Child2.
Control-drag from each container in Parent onto the child view controller you want to appear in that container. When prompted, select that you want to create an "embed segue".
An embed segue tells your app that it should load the child view controllers when Parent is loaded, and make their content views subviews of the container views.
In Parent, the PrepareForSegue() method will fire as each child view controller has been initialized and its view is getting ready to be loaded. At that point you can pass information to the child view controllers, set up delegate links, etc. (Note that you can't, and shouldn't, manipulate the child view controller's view hierarchies directly. Instead, pass data to the child view controllers using proprerties or methods of those view controllers, and have the children's viewDidLoad methods install that data into the views as needed.
I was reading the documentation:
You need to decide how many children can be displayed by your view
controller at once, when those children are displayed, and where
they appear in your view controller’s view hierarchy.
But in which method should I position the view controller children's view? Say I have two UIViewController in the container and I want one next to the other.. how do I do this?
In one of my articles I demonstrated how to create a simple dashboard app using UIViewController Containment.
http://www.highoncoding.com/Articles/848_Creating_iPad_Dashboard_Using_UIViewController_Containment.aspx
Each of the child view controllers has a view property. You can set the frame of those views when you add them to your own view.
It depends on the context of the situation that you may have. If you need to display all of the children when displaying the view for the first time, then add the view controllers and views in viewDidLoad ( if using a xib or nib) or in loadView ( if done programatically). If you need to show the child view controllers on demand, like after the touch of button, then you can add the child view controller and associated view in a separate method.
You will need to layout the views of the child view controllers as you would layout any other subviews. Remember view controller containment is just another ways of allowing you to modularize your code.
Check out this link which helps explain how to add the child view controllers: Animate change of view controllers without using navigation controller stack, subviews or modal controllers?
Here is a simple sample project that shows how to add child view controllers:https://github.com/toolmanGitHub/stackedViewControllers
Good Luck!
I have a scrollview that has a page control. The scrollview contains 3 views. Each view contains a view controller. In one of my view controllers I press a button and I want the scrollview to scroll to a specific location. But Im not sure how to accomplish that since the button is not in the UIScrollview but in one of the view controllers. Could anyone point me in the right direction with this? I have spent a lot of time trying to follow the view hierarchy to see if I can send a message to the scrollview for it to scroll. Any help is appreciated.
You can:
Add a delegate in your 3 inner View
Controllers that points to the View
Controller that holds your Scroll
View.
Create a method in the View
Controller that holds the Scroll
View that will call [scrollView
zoomToRect:] when called.
Access it from your 3 inner View
Controllers using the delegate.
If you need more information about delegation. check what is Delegate in iPhone?.
I have an app built from the UITabBarController starter project. The first tab is part of the main.xib that contains the tab bar. I would like to slide a view up from the bottom on top of that tab's view that only covers part of the screen. My understanding is that you can only cover part of the screen if you make the top view non-modal, but I don't see a way to do that without a NavigationController.
How can I do this?
you can add a UIView as a subview to the current view, and then animate its appearance into the screen using animation blocks, or Quartz or however you would like.
presentModalViewController: is actually a method that belongs to UIViewController, the superclass of UINavigationController, so you can use it from any view controller, not just a navigation controller.
Have you tried using a UIActionSheet? That's an easy way to get a view with a few buttons for user input to slide up and only cover the bottom portion of the current view.
I have created an iPhone application based on an OpenGL view. Now I
would like to show a "settings" form. Since my code runs in UIView, I have no pushViewController. How do I show a view controller on screen?
Thanks!
You can do this in one of two ways:
You can create a new view hierarchy, and then add it as a subview of your UIWindow when you want to show preferences. When you're done with your prefs, you can animate it out and then remove it as a subview.
You can switch to a UINavigationController/UIVIewController based hierarchy, and hook your current OpenGL/UIView to a UIViewController's view outlet. Then you can use all the regular UINavigationController based navigation stuff.