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
Related
After I added an UIView into one of my UIViewController I noticed SafeArea size is shortened from bottom about 40 and when I select the UIViewController it applies the effect all other UIViewControllers. When I click any other UIViewController, all displays back the SafeArea to its original size excluding the UIView added.
I deleted the UIView I added and see if it going to fix the issue but it did not.
More info about setup: UIViewController's UIViews are separated into three parts. Header-Content-Footer. All of their items has UIStackViews. I added the UIView into Content view.
When I run simulator I don't see any gap in the bottom, it looks as I intended.
Please let me know, if you need any more information/clarification.
EDIT: I noticed I have two SafeArea inside the UIViewController. Do not how this happened and how to remove one created under Content UIView.
EDIT 2: Here is the photo of the duplicate SafeArea in the StoryBoard.
I created another UIViewController and copied the content needed there.
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.
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.
I am working on a Swift iOS8/9 project and using Xcode 7, with storyboard / autolayout, etc. (For completeness: I started at the beginning on the year on older versions of Xcode, etc.)
I have a a UINavigationController hierarchy and some View Controllers contain a single UIView which contain a single child, a UITableView. (I am choosing not to use UITableViewController, so suffice to say ... it is not an option.)
The problem: The tableview starts 64 pixels (status plus nav height) too low:
Now: I've had things working for some of my UIViewControllers containing a UICollectionView within a UIView but I achieved it (after lots of poking / prodding, and a while back) by a top alignment constraint from the top of the UICollectionView to the top of the Top Layout Guide. (Looking through my storyboard I some alignments and some vertical distances, but all to top of Top Layout Guide.)
I am looking for help understanding if I can do what I want, if the approach of constraining the top of the tableview to the top of the layout guide is correct, or if there is a better way.
Unfortunately, I cannot seem to repeat this (perhaps 'cos I've forgotten some key press combination jujitsu, or new Xcode, or collection != table, or something in my view hierarchy. (I've checked all segues are adaptive push, I've even deleted/re-built this VC since I had one model segue, just in case it was confused that this VC isn't in a navigation view controller hierarchy.)
If I control/drag to connect or select the two to align:
this is what I am offered - note no "align to top":
Note: Here are the table settings that (to my understanding) should be adjusting edge inset and scroll offsets correctly, and do appear to ('cos it is the only child of the top view, per documentation.)
Here are the frames after view did layout subviews:
The approach that I ended up using came to me when I spoke to #ProgrammingBonn and mentioned the frames. I saw that the primary UIView was position as I wanted, and so it (finally) dawned on me to align the top of UITableView to the top of the UIView.
(I suspect that much as I was building my own ViewController and not relying upon UITableViewController I had an over inflated view of this particular view within the hierarchy. It was a subview not a primary view, despite occupying all the screen real-estate.)
So, to be clear:
I selected the UITableView, then command/selected the UIView (the main one, and it's parent) and then used the "align" tool to top align those two.
Try unchecking the "Adjust Scroll View Insets" option.
I am not sure whether this will fix your problem but have you tried playing around with viewController.edgesForExtendedLayout?
See more info here:
Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7
I am developing an iPhone application for ios 7.1. The ViewController hierarchy is like "NavigationController -> UIViewController -> UIPageViewController -> UITableViewControllers". NavigationBar is hidden. Status bar is present. Everything is done programmatically. No storyboard/Xib is used.
In the UIPageViewController, I am creating a custom Title view (similar to the Navigation bar, but inside its own view). Hence the child controller's view (UITableView) should be pushed below this Title View. I have tried adding a constraint ("V:[TitleView]-0-[ChildView]"), after setting translatesAutoresizingMaskIntoConstraints of child view to NO. But this resulted in a blank screen (except for the title view). Changing frame of the child view etc and all did not have any effect.
Apart from setting the above flag and adding the constraint, I have not added/modified any auto layout/auto resize related settings. The application supports only the portrait mode (Home button down). There is not going to be any other dynamic layout change either. Appreciate if you could help in resolving this issue.
Following is the solution I ended up with as of now. Project was on hold for some time, and now being rewritten in Swift. Hence the below code is in swift.
//in the UIPageViewController
override func viewDidLayoutSubviews()
{
super.viewDidLayoutSubviews()
let scrollView = view.subviews[0] as UIView
scrollView.frame = CGRectMake(scrollView.frame.origin.x, 64, scrollView.frame.size.width, scrollView.frame.size.height - 64)
}
Basically I am moving and resizing the Page controller's default scroll view below my title view. I have to admit that I am not very happy with the solution. I feel that there must be some better alternative. (To make it safer, you can iterate the subviews to find the scroll view).
Look at the autoresize constraint from your page view controller and set it to false.
I think it's not the child which are autoresize but the pageviewcontroller frame.