TOSegmentedControl icon indicating copy to clipboard operation
TOSegmentedControl copied to clipboard

Smooth UIPageViewController integration

Open ppamorim opened this issue 6 years ago • 5 comments

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.

ppamorim avatar Jan 20 '20 20:01 ppamorim

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 avatar Jan 27 '20 16:01 TimOliver

@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.

ppamorim avatar Jan 27 '20 17:01 ppamorim

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. :)

TimOliver avatar Jan 29 '20 06:01 TimOliver

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 avatar Aug 29 '20 10:08 TimOliver

@TimOliver I will do thanks!

ppamorim avatar Sep 01 '20 08:09 ppamorim