Auto-Layout and PageViewController - ios

I have a simple controller with a container, I want to use UIPageViewController inside this container however I have a small problem with auto-layout on my child VC.
Here is my storyboard, I have a single label in my left VC which is at the center of the view.
When I set an embed segue from my container to my left VC I have no issue with label position :
However when I set my embed segue to my EndGamePageViewController which is supposed to present my left VC I have this issue with auto-layout :
I have already look at other relative questions such as this one, but this does not change anything, I have also tried to add
self.view.setNeedsLayout()
self.view.setNeedsUpdateConstraints()
in the viewDidLoad of my left VC but this does not work, if anyone can help me figure this out, this would be great.
Thanks.

Related

How to create a view that slides over another? from top to bottom or bottom to top

I'm interested in creating a view(controller) that is slideable over another.
For example, I have a container view with two VCs,
i want the bottom VC to be able to be dragged all the way to the top, covering the VC on top.
I know I need a PanGestureRecognizer, but not sure if I should be creating these viewcontrollers in storyboard or doing all of this programatically.
So far I have two viewcontrollers, in a containerVC, displaying all the content correctly. What I don't know is how to add a gestureRecognizer to the bottom VC and manipulate the position.
Should I add the recognizer to the ContainerVC, or to the ViewController that I'm dragging?
I am no sure what you want to do, but to me seems like a SideBar Menu. Theirs is a lot of libraries or implementation of that on the internet, I will put a link bellow, maybe it can help you, even this was not your idea.
https://github.com/jonkykong/SideMenu
Hope it helps, somehow

iOS layout view to fill device screen

This should be a very basic question, but I have tried a lot of things and it isn't working. :/
I have a single view application which consists of a single, full-screen custom view. I had my view class set on the main view of the view controller, but the status bar was always overlaid on my view.
Apple says to fix this, constrain your view to the top layout guide, but that requires I move my view to be a child of the main view. So I moved it, but now I can't set up constraints to simply make my view fill 100% of vertical and horizontal space.
I have tried doing it in code, using constraints, stacked views, anything I can find, but to no avail.
So, the hopefully simple question is, how can I make a single UIView child of the main view of a view controller size to fill the container and account for the status bar? The UIView is a custom class, so if code is needed I can do that.
I have tried overriding the intrinsic and size that fits methods, but they created terrible results.
You can do this programmatically:
let childView: UIViewCustom = UIViewCustom()
childView.frame = rootView.frame
childView.bounds = rootView.bounds
rootView.addSubview(childView)
Or via IB:
first select your childView, then click on the pin button in the low-right corner of XCode, disable Constrain to margins, then click on each red bar and set to zero the constrain. Finally click on Add 4 Constraints
Hope it helps.
try this:
0.Assume that you have a custom class just for View (not ViewController) named AAA.
in Main.storyboard, drag a "View" from Object Library to your ViewController. Call it ViewB.
2.set the viewB layout and constrains
3.select the viewB and go to its identify inspector(3rd small button on the right panel)
4.in the class section: write it as: AAA
Hope this will help you.

AutoLayout Not Working For 5.5" iPhone

In my app, I have a screen that needs privacy, so when you first open it, it will check if you have logged in with the password. If not, it adds another view on top of the SuperView until that password is entered. I use XIB file for this. The main View of the screen is a tableview, and I drug on another UIView to use as the Password screen. However, despite AutoLayout, the Password view is only taking up the dimensions of 4.7" phone, meaning you can see behind it on the edges. I made sure AutoLayout is enabled, and on the background image, which is the gradient, I added 4 constraints, one for each side, set to 0, so that it would always cover the view behind it, and then set the UILabel to be aligned horizontally in container. What am I doing wrong? This works PERFECTLY in a different view and XIB within the same app, and I even copied the view straight over, but it is still messing up on this one class.
Code to load this is (password is the UIView declared in the header as IBOutlet UIView *password:
[self.navigationController.view addSubview:password];
The correct solution is to use a view controller to manage the curtain view, and either push that view controller onto the navigation controller's stack, or present it from the navigation controller or the tab bar controller.
There may be 2 possible reason
you may not applied constraint on your xib.
you have applied constraint on it but when you are initialising your xib you are providing fix frame.
it would better if your share your code how you are doing it ?

UIPageViewController's child ViewController acting weird

I have a UIPageViewController (parent) managing multiple UIViewControllers (children). Children VC only have 1 UIImageView with the the following constraints: 0 px to left and right, 0 px to Top layout guide, 20px to bottom layout guide
When I change page in Forward direction, it behaves correctly. When I change page in Backward direction, said UIImageView seems to cover the whole space (similar to what it would look like if it had no constraint) during the transition animation, and when the transition is done, it corrects it's position.
Long story short, when going flipping page backwards, the image appears bigger during animation, and then it changes to the correct size. Why is this happening?
PS: I created a boilerplate "Page based application" and it doesn't happen
Edit: My storyboard nest a couple of VC like this: TabBarController -> UINavigationController -> UIPageViewController. The VCs hosted by pageVC are added dynamically in code.
I already tried setting the UIImageView constraints to the parents and I noticed 2 things:
The top part of the image is being hidden by the navigation bar.
The problem persist
Any ideas?
Edit: 2
My NavigationController host a VC that pushes UIPageViewController (maybe this is not how it's supposed to be done?) , so I don't really "add" the UIPageViewController through code. I add it's children through code. Here's a SS
Moreover, the children are just a UIViewController with a UIImageView with 0 constraint to the container view (not the layout guide), so it covers the whole space.
The problem is the frame of the of UIPageViewController, when we instantiate it from the storyboard the view frame is equal to the screen frame (without the topLayoutGuide and bottomLayoutGuide) and also the childs view controller take the same frame...
So to fix that we have two solutions :
The first solution
Add the topLayoutGuide and the bottomLayoutGuide constraints to the imageView, but with this solution we get some problems with animation, because the frame is calculated only when the page is completely shown (you can find more details here : https://stackoverflow.com/a/29589531/2477632)
The second solution
1- Instantiate differently the MagazinePagesViewController : Create
MagazinePagesViewController with UIViewController super class (and
not UIPageViewController)
2- Add programmatically a pageViewController
let pageViewController = UIPageViewController(transitionStyle: UIPageViewControllerTransitionStyle.Scroll, navigationOrientation: UIPageViewControllerNavigationOrientation.Horizontal, options: nil)
pageViewController.view.frame = view.frame //add also some constraints if needed to support rotation
view.addSubview(pageViewController.view)
addChildViewController(pageViewController)
pageViewController.didMoveToParentViewController(self)
If needed I can upload the sample code with these two solutions.
Hope that helps

Placing a control over a mapview iOS 7 using storyboards

I'm trying to place a button over a mapview. In storyboard I have it as the last control in the view hierarchy, the map view still covers it up. I've tried adding this line in my viewDidLoad method to bring my button view to the front but it doesnt seem to work either
[self.view bringSubviewToFront:self.flagButton];
anyone have any idea why this wouldnt be working? the map view covers most of the screen, and I want to place a few buttons on top of the map, but so far can't get them to show up, they are under it every time.
I was able to do this by making my view as subview of map view.
first,
self.view = self.gmsMapView;
then,
[self.gmsMapView addSubview:_myBtnView];
I know this is an old post, but I'm answering for the sake of someone facing the same problem.
I was having the same issue, then I found a solution, and is as follows:
First, open your project and go to your StoryBoard then click on "Show Document Outline" switch that is on bottom left very small switch. After that select your "Scene" that you are having problems with then click "View". Find your MKMapView object and drag it up until you reach the first row. This will make your MKMapView object (or any other) "the first in a layer" so to speak.
I hope someone will find this helpful.
E
I was using storyboards and was not seeing the button. I had to set the MKMapView to hidden until the button was displayed and in position. Then I set the MKMapView to visible.
Here are the steps I had to take in the interface builder to get my button to show
Create a UIViewController which contains a view
Add an MKMapView and set constraints
Add UIButton in the same view as the MKMapView, set the image and text, whatever is applicable. If MKMapView disappear when you try to resize or move the button, the map view has just set its width and height to zero. Enter new values in the Size Inspector for the map view and it will resize back. Or you can move the button elsewhere off the MKMapView and then move the button back to where you want it.
The important part is to set constraints for the UIButton. I also had to set the MKMapView hidden until I got the size and placement right and then set it back to visible.
Here's how it looks in the simulator
You can't add a subview to an MKMapView via the storyboard. Add it as a sibling view instead.
Edit: Your map view should also be a subview of the root view (i.e. self.view) for this to work.
I was having similar issues and I did the following:
Made sure both the map view and the button are at the same level in the view hierarchy, I accomplished this by creating a View that both the map view and button were children of.
Made sure the button is dragged below the map view in the left gutter of the storyboard (so it is actually rendered on top).
Made sure there were valid constraints for the button.
The only thing new that hasn't already been mentioned was double-checking the constraints, and that appeared to resolve it for me. Hope that helps.

Resources