I’m going for a Facebook-esque slide-over UITableView.

I’ve accomplished that, animation and drop shadow and everything. My worry is that I’m doing it the the completely wrong way, and that come things don’t work completely right.
The application has a rootViewController (of the UIWindow) that is a UINavigationController. A view inside the UINavigationController (its root view controller) has its leftBarButtonItem property set. Here is the code that runs when the button is pressed.
- (void)showFeedList {
//set the feed list as showing even before it is
feedListShowing = YES;
//to show the feed list, we need to instanciate one
feedSelectionListViewController = [[FeedSelectionListViewController alloc] initWithNibName: @"FeedSelectionListViewController" bundle: nil];
//set the frame to 200 points to the left of the screen
feedSelectionListViewController.view.frame = CGRectOffset(feedSelectionListViewController.view.frame, -200, 20);
NSInteger offset = feedSelectionListViewController.view.frame.size.width;
//store a pointer to the root navigation controller, and add the list view controller's view to the navigation controller's view
UINavigationController *navigationController = (UINavigationController *)UIApplication.sharedApplication.delegate.window.rootViewController;
[navigationController.view addSubview: feedSelectionListViewController.view];
//animate the navigation bar, feed selection list, and this view controller's view to the right
[UIView animateWithDuration: LIST_SHOW_TRANSITION_TIME animations: ^{
self.view.frame = CGRectOffset(self.view.frame, offset, 0);
navigationController.navigationBar.frame = CGRectOffset(navigationController.navigationBar.frame, offset, 0);
feedSelectionListViewController.view.frame = CGRectOffset(feedSelectionListViewController.view.frame, offset, 0);
}];
}
This is really messy, and not everything about it works right. First, when the user leaves and comes back to the application, the UINavigationBar seems to have reset it’s frame. This also happens when the in-call status bar is toggled on and off. Secondly, any views inside the view on the right do not move to the right as they should. I do not know why this is.
However, if I replace the animation block with
navigationController.view.frame = CGRectOffset(navigationController.view.frame, 200, 0);
It works fine. The subviews of the view currently displayed by the navigation controller move accordingly, and everything is in the right place when the application is resumed. However, the sidebar view is not receiving touch events, touches that are made over the sidebar are now handled by the AppDelegate. I’m suspecting this is because the frame of the UIView has an origin of {-200, 0}, though I cannot be certain.
I don’t think I’m understanding something. Is this even the right way to be doing this? I can’t think of any other ways to be doing it. Anyway, super thanks in advance for any guidance or suggestions.
-matt
What you’re looking for is already provided with this library of mine https://github.com/pkluz/PKRevealController
Does exactly what you’re trying to do. It’s slim and ready to use. Implementing it by yourself over again would just prevent you from working on your actual app 🙂
Problems I encountered during implementation as well as what I can tell from skimming over your code are various. Primarily it’s the fact that you’ll have problems because you’re abusing the view hierarchy.
You basically now have two UIViewControllers taking care of your iPhones screen. That wasn’t intended by Apple at first as it was thought that at any point in time there’d only be a single ViewController present. – This changed with the iPad, and the UISplitViewController. And just recently in iOS 5 the new API made it possible to add your own ViewControllers to the heirarchy.
The problem you’ll be having is that your FeedSelectionListViewController will have difficulties receiving viewWill/Did/Appear/Disappear and/or rotation calls as it’s not actually part of the chain.
So my answer is to either check out the library I provide or look into UIViewController Containment first, because your code isn’t exactly fixable seeing how it’s generally not the right approach, even though it might work under certain conditions.