How to remove the bottom gap of UIPageViewController
Finally got the solution myself I just hide the page control from UIViewPageController and then extended the size of the UIPageViewController to cover up the gap left due to absense of page control.
NSArray *subviews = self.pageController.view.subviews;
UIPageControl *thisControl = nil;
for (int i=0; i<[subviews count]; i++) {
if ([[subviews objectAtIndex:i] isKindOfClass:[UIPageControl class]]) {
thisControl = (UIPageControl *)[subviews objectAtIndex:i];
}
}
thisControl.hidden = true;
self.pageController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height+40);
ios UIPageViewController, how to remove bottom's gap?
There are several solutions mentioned in this post! Here they are: Either switch the transition style from UIPageViewControllerTransitionStyleScroll
to UIPageViewControllerTransitionStylePageCurl
or implement the following code in the viewDidLoad:
NSArray *subviews = self.pageController.view.subviews;
UIPageControl *thisControl = nil;
for (int i=0; i<[subviews count]; i++) {
if ([[subviews objectAtIndex:i] isKindOfClass:[UIPageControl class]]) {
thisControl = (UIPageControl *)[subviews objectAtIndex:i];
}
}
thisControl.hidden = true;
self.pageController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height+40);
It will automatically hide the pageControl indicator.
IOS PageViewController extra white space at bottom
The "blank space" is almost certainly the Page View Controller's built-in UIPageControl
.
Here's a quick example, with two views... the top view has a UIPageViewController
added as a child view controller, and the Top of the bottom view is constrained to the Bottom of the top view:
Notice the "empty space" ...
Using Xcode's Debug View Hierarchy, it's pretty obvious why:
So, if I set a background color on the Top view, I see this:
It appears to be empty space, because the default Page Control uses tinted white dots - so we don't see anything on a white background.
Edit
The PageControl is automatically shown if your controller's DataSource
implements both of these optional methods:
optional func presentationCount(for pageViewController: UIPageViewController) -> Int
optional func presentationIndex(for pageViewController: UIPageViewController) -> Int
Removing one or both will automatically remove the page control.
Preventing the white gap that appears on swiping UIPageViewController
The origin of the bug is the constraints of your UIImageView.
When you begin scroll, only viewWillAppear is called, and autolayout is not yet calculated, when the scroll is finished, and view is shown, the view start calculate autolayout, and viewDidAppear happens after autolayout is completed.
you can check that by adding the code below in PageContentViewController
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = UIImage(named: "UpcomingGamesBg")
println("viewDidLoad imageView Frame : \(imageView.frame) pageIndex : \(pageIndex)")
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
println("viewWillAppear imageView Frame : \(imageView.frame) pageIndex : \(pageIndex)")
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
println("viewDidAppear imageView Frame : \(imageView.frame) pageIndex : \(pageIndex)")
}
And because, the layout of your imageView refer to top layout guide, and top layout guide can have different value before and after calculating autolayout, you have this bug.
So to resolve that, you can change the constraints of your image view and make them relatives to the parent view (because the pageContentViewController is like a subview and the the pagerViewController will manage the top and the bottom margin), like that :
With that you can fix this bug, but be careful you should add some contraints to your pageViewController.view
Update
For example to support navigationBar / TabBar, you should add some constraints in viewDidLoad (after view.addSubview(pageViewController.view)
):
pageViewController.view.setTranslatesAutoresizingMaskIntoConstraints(false)
let topConstraint = NSLayoutConstraint(item: pageViewController.view, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: topLayoutGuide, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0)
let bottomConstaint = NSLayoutConstraint(item: pageViewController.view, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: bottomLayoutGuide, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 0)
let leadingConstraint = NSLayoutConstraint(item: pageViewController.view, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Leading, multiplier: 1.0, constant: 0)
let trailingConstraint = NSLayoutConstraint(item: pageViewController.view, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Trailing, multiplier: 1.0, constant: 0)
view.addConstraints([topConstraint, bottomConstaint, leadingConstraint, trailingConstraint])
Best regards,
UIPageViewController Creating a Border at the Bottom of my UIImage and how to get rid of it
I managed to overcome this implementation with the selected answer in this question here How to remove the bottom gap of UIPageViewController
The basic premise is to ensure I'm extending out the PageViewController's view by 15 which moves the page indicators to the bottom. Luckily my background is black (the purple images above in the question were for reference) and the image doesn't look squashed. While this isn't an ideal solution, it does the job for now.
How to change position of UIPageControl in iOS =8.0?
Yes, you can add custom page controller for that.
self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 50, self.view.frame.size.width, 50)]; // your position
[self.view addSubview: self.pageControl];
then remove
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
and
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
Then add another delegate method:
- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray<UIViewController *> *)pendingViewControllers
{
PageContentViewController *pageContentView = (PageContentViewController*) pendingViewControllers[0];
self.pageControl.currentPage = pageContentView.pageIndex;
}
Related Topics
iOS Library to Convert Powerpoint Presentations into Images
How to Add Navigation Interface After Create a Tab Bar Controller Programmatically (Swift)
Enabling Facebook Breaking Changes Feb 2013: Login Does Not Work
Handing Firebase + Facebook Login Process
Set the Status Bar to Black Colour
Xamarin.iOS Binding Libraries/Native Frameworks
Show Data in Uipickerview Second Component Based on First Component Selection
Displaying Text One Character at a Time in Swift 2.0
The Proper Way of Doing Chain Animations
How to Switch to Speaker Output When Bluetooth Headsets Are Connected
Store Time Efficiently in Firebase Database
Swift Spritekit Facebook Share Button
Replace iOS App Emoji with Twitter Open Source Twemoji
Unrecognized Error in Mapview (Ios)
Add Button at the End of Collection View in Storyboard
How to Use Avcapturephotooutput to Capture Photo Swift + Xcode
Position a Subview on the Edge of a Circular Shaped View
How to Save Custom Objects in Array and Store It in Nsuserdefaults - Iphone