Smooth UIPageViewController integration
Hi,
I would like to know if it's possible to use the delegate from UIPageViewController to control the X axis movement of this custom UISegmentedControl. This allows smooth transitions of pages.
Something like this can be done:
segmentedControl.pageViewController = self
So the segmentedControl listens the UIPageViewController and animate it automatically.
Thank you.
Hi @ppamorim!
Hmm, this is a super specific use-case. It's definitely possible to do, but it would require a fair bit of effort to access the page view controller's state, and map that to the segmented control.
This is a little too specific to be implemented inside the segmented control class. But instead, I'd suggest what you could do is implement your own controller object that is in charge of linking up the segmented control and the page view controller, and handling all of the state between the two.
If you wanted to directly attach the segmented control's handle to the page view controller, it would require you to access the internal scroll view of the page view controller.
To manually control the position of the handle, you could wrap the setSelectedIndex method in a UIViewPropertyAnimator object and manually advance or retreat the animation progress.
I hope that helped! Sorry I couldn't do more!
@TimOliver Maybe just expose the X position of the current item selected so it's easier to modify? So we don't need to implement anything to handle the internal scroll view action direct.
That's not a bad idea! It would be pretty easy to make a property like thumbHorizontalOffest and segmentWidth to control the positioning and determine which segment is active.
I don't have the time to do commissioned new features, but if you want to try and add it as a PR, I'd be happy to guide you. :)
Hi @ppamorim! @kim-kiori-d has created a PR with the aim of supporting what you were asking for. If you're still interested in this functionality, would you like to take a look at it? :)
@TimOliver I will do thanks!