I'm developing an iPad application and I need to create an UIView
that is always on top in respect to other views.
A is the area (consider it as a sort of sidebar) where I need to create a UIViewController
which view remains always on top. B, instead, is the content area where a UIViewController
(with its view) can change: depending on several button actions (inside A's view), it's possible to remove the current visible content (in this case controller B and its view) and display other controllers (C, D, E, etc.) with theirs views.
I created all the elements for my application but I have problems to maintain A's view on top and, at the same time, implement the logic used to dinamcally change the content area. As requirements I need that A always overlaps B. In other words, a portion of B (the left part) is always under the area of A. B always extends the entire device screen.
Could you give me some advice?
I made two configurations but I have problem with them.
First Configuration
In the first one, I created an UIViewController
for A (called SideBarController
). I added SideBarController
view to UIWindow
(within the application delegate). Then I created an UIViewController
for B (called HomeViewController
) and I added it as a rootViewController
for my application.
This solution could be a valid one because I can change the content area dinamically (setting a new rootViewController
) through my application delegate but the SideBarController
remains always under the current visble view.
Second Configuration
In the second one, I created an UIViewController
(called MainViewController
) and I added it as a rootViewController
for my application. Then within MainViewController
I created an UIViewController
for A (called SideBarController
) and I added SideBarController
view to MainViewController
. Then the content area has been filled creating an UIViewController
for B (called HomeViewController
) and adding it to MainViewController
.
The sidebar remains always on top but I have difficulties to change dynamically the content area within MainViewController
. How is it possible to access the content area and change it?
Note I'm aware about standard components on UIKit but I need to implements such a solution because of user specifications.
I would begin by trying to implement your sidebar in a UIPopoverController
. It's designed pretty well for this kind of problem, and you can customize it extensively to meet your UI needs. If UIPopoverController
causes you some kind of problem, I'd put the sidebar in its own UIWindow
and float that over the main window.
EDIT
Personally I'd go for the popover myself since it's more built for this kind of issue. Another thought that comes to mind and I've used in the past is a UIView
that you add to directly to the UIWindow
([view window]
from any view will get you the main one). Remember, UIWindow
is just a special kind of UIView
. The problem with this and the UIWindow
solution is that you will have to do your own rotation logic which can be trickier than it sounds if you have autorotations. UIPopoverController
handles all this very cleanly and automatically if you can use it.
If you pursue UIWindow
see the Windows section of the View Programming Guide: http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingWindows/CreatingWindows.html