Correct approach to create a text carousel using UIPageControl
I am trying to reproduce a simple text carousel with a UIPageControl similar to the following login screen:
I've created the following layout (view -> label , text):
EDIT: I found some tutorials like: http://www.appcoda.com/uipageviewcontroller-tutorial-intro/ which uses UIPageViewController
however the result of "masking" my entire view disabled my existing interface.
Problems that arose :
- I want multiple paragraphs to be similar to the layout I created, should I create them without constraints? - not just create one view as a "template"
- How can I split a string in a textbox using the interface constructor? -developed by: ALT + Enter
- What is the correct way to animate the inbound and outbound layouts? - use UIPageViewController, don't animate views
- Or maybe there is a library that will make my life a lot easier , maybe I found the solution straightforward (at the end)
Q: How would you implement such a function? any good tutorial?
source to share
I used @Shlomi Schwartz's project and found an error when I used more than 3 UIPageViewController
(try with 4 UIPageViewController
, for example using @Shlomi Schwartz's project). The problem came from a missing and unimplemented extra UIPageViewControllerDelegate method that was driving the UIPageControl insane.
Please find a specific method that fixes the error below:
/*
Optional UIPageViewControllerDelegate method
Sent when a gesture-initiated transition ends. The 'finished' parameter indicates whether
the animation finished, while the 'completed' parameter indicates whether the transition completed or bailed out (if the user let go early).
*/
func pageViewController(pageViewController: UIPageViewController,
didFinishAnimating finished: Bool,
previousViewControllers: [AnyObject],
transitionCompleted completed: Bool)
{
// Turn is either finished or aborted
if (completed && finished) {
let currentDisplayedViewController = self.pageViewController!.viewControllers[0] as! ContentViewController
self.pageControl.currentPage = currentDisplayedViewController.index
}
}
If you would like a complete working draft, please find the Github link below:
Note: Thanks again @Shlomi Schwartz for sharing the original snippet with the community (very helpful). I also remember to mention him as the main author in the source code.
source to share