My view controllers are structured like this:
> UIWindow
> - RootViewController with UIScrollView (2 pages, pagingEnabled)
> -- UINavigationController (in the first page of the scrolling view)
> --- HomePageViewController (plus other ViewControllers pushed on the stack)
> -- MinutiaViewController (second page)
UIScrollView holds the UInavigationController as a subview
[scrollView addSubview:navController.view];
In my scenario I want to:
disable UIScrollView scrolling (scrollEnable=NO) once a new view is pushed onto the UINavigationViewController
enable UIScrollView again (scrollEnable=YES) once the new view is popped and the UINavigationController shows its root again
(HomePageViewController)
I figured out how to disable the scrollView scrolling when pushing a new view.
But cannot figure out how to enable the scrollView scrolling when the new view pops off the stack.
So far I tried
1 triggering viewWillAppear; viewWillDisappear; manually and sending a
message to UIScrollView from HomePageViewController's viewWillAppear
e.g.
[self.navigationController.parentViewController performSelector:#selector(enableScrollAgain)];
2 designated the RootViewController as a UINavigationController delegate to handle its
events
None seems to work so far. All advice appreciated!
Have you tried using Notifications ? You could add the RootView to observe a notification form the navigation controller, when you get that notification you can disable scrolling. Look into NotificationCenter.
Hope this helps
Related
I have a UIScrollView that houses three UIViewControllers so that I can swipe between them like the view setup in SnapChat.
In my ViewController on the very right of the UIScrollView I want the user to be able to select things and then navigate to a new page. So essentially I want the right-most UIViewController to be a Navigation Controller with a nav bar and and View Controllers I navigate to from this page should also have a nav bar and a Back button as the UIBarButtonItem in the top left as standard.
I went about it the normal way, just taking the View Controller and selecting "Embed In Navigation Controller" and looking at the storyboard it looks right, but if I run it, there's no nav bar at the top of the view controller.
I have the nav bar visibility set to "Show Navigation Bar" but still nothing.
Any help appreciated
Edit
The issue is more than likely to do with how I add the view controller to the UIScrollView which is as follows:
let settingsStoryboard = UIStoryboard(name: "SettingsView", bundle: nil)
let settingsViewController = settingsStoryboard.instantiateViewController(withIdentifier: "SettingsViewController")
self.addChildViewController(settingsViewController)
self.scrollView!.addSubview(settingsViewController.view)
So I'm only adding the view. So how would I add it as a Navigation Controller? Or can that be done?
The Problem you are facing is that you are adding your view controller directly inside the scroll view but you should add the navigation controller inside the ScrollView.
So go to story board create a StoryboardID for that navigationController which is attached to SettingsViewController and then replace the SettingViewController ID with your navigationController's Storyboard ID.
maybe use addChildViewController
- (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(5_0);
I have a window with a UITabBarController as rootViewController. The UITabBarController has two children: A UINavigationController and a UISplitViewController (according to the latest docs this should be OK, and it works except for the following problem).
Both the UINavigationController as well as the UISplitViewController show a MyMasterTableViewController which can push instances of MyDetailViewController.
MyDetailViewController has self.hidesBottomBarWhenPushed = YES to make the TabBar disappear on push.
When I push MyDetailViewController onto the UINavigationController the UITabBar disappears as expected. When I show MyDetailViewController on the UISplitViewController while it is collapsed, I would expect the same, since the collapsed UISplitViewController contains only a UINavigationController with the Master which pushes the Detail ViewController. It doesn't however.
How can I let a collapsed UISplitViewController make the UITabBar hide on showing MyDetailViewController like the UINavigationController does?
Unfortunately you cannot take advantage of Hide Bottom Bar on Push while using a UISplitViewController inside a UITabBarController. You can override the UITabBarController viewControllers and for the iPhone only, point to the MasterViewController's UINavigationController in the Storyboard. This is where you can Hide Bottom Bar on Push. The UISplitViewController for some reason does not respect the flag on a push, probably for iPad purposes.enter image description here
I have initialized a UIViewController with a nib file which displays fine when I push it on my viewstack.
However when I try and present it as a modal viewcontroller, the view of that controller is clipped at the bottom during the transition animation only. After the transition is done, the view displays just fine.
Anyone have a clue what is going on here? Do I need to set additional properties on my viewcontroller that is presenting my modal viewcontroller?
I have tried re-setting the frame of my viewcontroller without success...
I added a subview to my application. The view controller is a UITableViewController. When I open the .xib file I see the table, but I can't drag a navigation bar onto it. So once the user enters the view, they have no way of getting back to the previous screen. What can be done?
the UITableView nib representation cannot have it. You can simulate the UI in the case you have a navigationController.
If you want to have a navigation controller, your UITableView has to be pushed into the stack of navigationController.
Assuming your view controller is ViewControllerA has a navigationController, then this method will make sure you have navigation controller in your UITableView:
[viewControllerA.navigationController pushViewController:tableViewController animated:YES];
I'm adding navigation to subviews in my app from the home view.
I understand the concepts of pushing and popping view in the navigation stack, however, I don't want the navigation bar in the home screen.
Basically, when the user leaves the home view to any sub view, I'd like them to see the "Home" button on the left of the button nav bar, but no nav bar in the home view.
Any help would be appreciated.
It sounds like you want to start out with a bare UIViewController, containing your home screen with your own custom buttons.
The UINavigationController should come into play only when a user performs some action. Do this by
[navVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; // pick an effect
[self.viewController presentModalViewController:VC animated:YES];
Where navVC is the navigation controller, and self.viewController refers to your (new) main view controller. (add a suitable line IBOutlet UIViewController *viewController; + #property line + #synthesize line)
You need to fiddle a bit in the way the app starts up, for now it will probably show the navigation controller directly. If you are using a xib, you can do this by adding a UIViewController while leaving the navigation controller there as it stands. In application: didFinishLaunchingWithOptions: you'll find a line saying
[window addSubview:...];
which actually determines which viewcontroller's view is first visible. Change this to:
[window addSubview:self.viewController.view];
If you've done all this correctly, you've inserted the extra UIViewController between startup and navigation.