Page View Controller Button Over All Views - ios

How can I add two buttons over all views in a page view controller. If I were to add them to each view separately, each swipe causes the buttons to be reloaded.
Is it possible to have buttons static over all views in a PageViewController, or would I need a container view with a page view controller inside?

It's just like any scroll view: pin the buttons to the frame of something outside the page view controller's scroll view. The page view controller's own view would do, or the window, or whatever.

Related

Is it *possible* to make your own Tab Bar Controller?

I have a project where our tab bar has a big middle button (that extends above the tab bar) and other custom behaviors including a badge icon and colored labels.
I got "smart" and decided to just write my own tab bar and tab bar controller to go with it. The problem I've run into is that when one of the tabs is wrapped in a UINavigationController, that view always takes up the whole screen (you can't capture a UINavigationController into a small subview) and so I have to manually inset the content on those views.
Is there a smart way to handle this? It feels gross to just cut the content short on each screen by 100 points...that doesn't feel right at all.
What approach should I take...or should I just automate the content insets programmatically?
A tab bar controller is just a scroll view with a view at the bottom that toggles between the scroll view's offset. I assume you want the tab bar controller to be at the root of your app, so in the root view controller, add a UIScrollView.
Then add the views of the view controllers (the tabs) to that scroll view, and anchor them appropriately so that the scroll view scrolls. Make the heights and widths of these view controllers full screen. Before you add them to the scroll view, you must create a parent-child relationship between the root view controller and its tabs.
self.addChildViewController(tabOneViewController)
tabOneViewController.view.translatesAutoresizingMaskIntoConstraints = false
scrollView.addSubview(tabOneViewController.view)
tabOneViewController.didMove(toParentViewController: self)
tabOneViewController.delegate = self // so that your tabs can communicate back to the controller
// add constraints
Each of these view controllers will ideally be or contain the navigation controller for that section.
Then just add the tab bar to the view of the view controller, not to the scroll view (add this after the scroll view so that it sits above the scroll view). This tab bar is just a regular UIView, most often anchored to the view controller's bottom safe area. Because its a part of the view controller's view, and not the scroll view, it has no impact on the content behind it.
The benefit of a custom tab bar setup like this is that you can navigate between tabs on tap or by pan gesture. To navigate between tabs by tapping on the buttons in the tab bar, simply change the scroll view's content offset:
// this would move to the third tab
scrollView.contentOffset = CGPoint(x: view.bounds.width * 2, y: 0)
Add your bells and whistles and you're set.

Collection View in View Controller, Cell touching the top border of Collection View itself (embedded in navigation controller)

so, i'm trying to make horizontal scroll collection view in view controller. The View Controller is embedded in navigation controller. So the view controller have little spacing on top of cell. And if i resize it, the cell gonna sink. Simply, i want the little spacing dissapear. Normally like Collection View inside view controller without embedded in navigation controller
i want this
to this
i want this
Embed a navigation bar and then drag the collection view. This should hopefully work. If it doesn't let me know..

How to create a view above navigation bar or other screen content?

I would like to have a view above the navigation bar, or above any screen content if there isn't a navigation bar on that screen, so that it essentially reduces the height of everything else and doesn't cover any content. I also would like this view allow interaction (i.e. if its tapped, it would do something).
I have tried
UIApplication.sharedApplication().keyWindow?.addSubview(view) but that just overlays the view.
Here is a visualization:
Don't think of it in terms of above, think of it as beside - a sibling view.
So, create your own root view controller with that view and a container view below it, then add your 'normal' root navigation controller (or whatever) as a child view controller into the container view.

UISplitviewController with sliding menu

My split view controller is set as the root view controller in my app delegate.
I need to slide my split view to the right (master and detail view) about 200px, while sliding in a menu view from left to right (left of the split view) at the same time which has a width of 200px. So my split view would slide off the main view while the menu view appears. Ive tried adding a subview to UIWindow which I beleive is not the right way to do it. Ive tried adding my menuViewController to my split view controllers' master view controller. But it doesnt seem to work. Help please!!!

How to add a segmented control anchored to the bottom of the screen below a table view in interface builder

I have a view controller (derived from UIViewController not UITableViewController) containing a table view. The controller and view are both within the same xib.
I want to add a segmented control to appear at the bottom of the screen, with the table view taking up the rest of the space above it.
However in IB it will not let me place the segmented control as a direct child of the view controller, it will only let me place it as a child of the table view i.e. the hierarchy looks like this:
Navigation Controller
Navigation Bar
Main View Controller - Item
Table View
Segmented Control - First, Second
Navigation Item - Item
Bar Button Item - Style
If I run it like this then the segmented control floats up and down depending upon how many items there are in the table view.
What can I do to get it to be locked to the bottom of the screen?
UPDATE:
I got nearer - I added a view as a child of the main view controller and made the table view and segment control children of that, but now only the top half of the control appears when I run the simulator but everything looks fine in IB, why is there a discrepency?
Side question - as a starting point I'm using one of Apple's sample project, why was there no main view? When should you and when should you not have a main view?
Thanks
Just open your xib and expand your view and drag Tableview control under View and also drag segmented control under view not in tablview this will work.
you need to set frame of both in you viewDidLoad
tblview.frame = CGRectMake(0, 0, 320, 400);
sgmntcontrol.frame = CGRectMake(50, 405,150 ,50)];

Resources