Search code examples
iosxamarin.iosuipagecontrol

When changing page by tapping on IOs PageControl speedily, the current indicator moves ahead of the page


In my Xamarin.IOs project, I have a UIPageControl that is combined with a Paging enabled UICollectionView.

I use the CardPageControl.PrimaryActionTriggered event to handle swiping the page.

CardPageControl.PrimaryActionTriggered += OnPageControlTapped;

private async void OnPageControlTapped(object sender, EventArgs e)
{
    // SetContentOffset of the collection view
}

But when I speedily tap on the PageControl, the current indicator moves way ahead of the current page and then after the tapping ended, the current indicator re-positions in the correct indicator.

enter image description here

How can I fix this?


Solution

  • You have to enable DefersCurrentPageDisplay. This is false by default.

    CardPageControl.DefersCurrentPageDisplay = true;
    

    Then inside OnPageControlTapped, invoke UpdateCurrentPageDisplay() of CardPageControl,

    private async void OnPageControlTapped(object sender, EventArgs e)
    {
        // SetContentOffset of the collection view
    
        CardPageControl.UpdateCurrentPageDisplay();
    }
    

    This will sync the PageControl current indicator with the current page.