I have a simple UIPageViewController which displays the default UIPageControl at the bottom of the pages. I wonder if it's possible to modify the position of the UIPageControl, e.g. to be on top of the screen instead of the bottom. I've been looking around and only found old discussions that say I need to create my own UIPageControl. Is this thing simpler with iOS8 and 9? Thanks.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
Just get the first view controller and find out the index in didFinishAnimating:
Swift 4 version of @Jan's answer with fixed bug when the user cancels transition:
First, you create custom pageControl:
You add it to the view and position it as you want:
Then you need to initialize the
pageControl
:Finally, you need to implement
UIPageViewControllerDelegate
, and its methodpageViewController(_:didFinishAnimating:previousViewControllers:transitionCompleted:)
:Now in comparison with @Jan's answer, we update
self.pageControl.currentPage
usingpageViewController(_:didFinishAnimating:previousViewControllers:transitionCompleted:)
(shown above), instead ofpageViewController(_:willTransitionTo:)
. This overcomes the problem of cancelled transition -pageViewController(_:didFinishAnimating:previousViewControllers:transitionCompleted:)
is called always when a transition was completed (it also better mimics the behavior of standard page control).Finally, to remove the standard page control, be sure to remove implementation of
presentationCount(for:)
andpresentationIndex(for:)
methods of theUIPageViewControllerDataSource
- if the methods are implemented, the standard page control will be presented.So, you do NOT want to have this in your code:
Here's my take. This version only changes de indicator when the animation is finished, i.e. when you get to the destination page.
here s a very effective way to change the position of the default PageControl for the PageViewController without having the need to create a new one ...
Yes, you can add custom page controller for that.
then remove
and
Then add another delegate method:
For swift:
remember use pageController.numberOfPages and delegate the pageView
then remove
and
Then add another delegate method: