首页 > 解决方案 > 快速点击 IO 页面控件切换页面时,当前指示器移动到页面前面

问题描述

在我的 Xamarin.IOs 项目中,我有一个 UIPageControl,它与启用分页的 UICollectionView 相结合。

我使用该CardPageControl.PrimaryActionTriggered事件来处理滑动页面。

CardPageControl.PrimaryActionTriggered += OnPageControlTapped;

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

但是当我快速点击 PageControl 时,当前指示器会移动到当前页面的前面,然后在点击结束后,当前指示器会重新定位在正确的指示器中。

在此处输入图像描述

我怎样才能解决这个问题?

标签: iosxamarin.iosuipagecontrol

解决方案


您必须启用DefersCurrentPageDisplay。默认情况下这是错误的。

CardPageControl.DefersCurrentPageDisplay = true;

然后在OnPageControlTapped内部,调用CardPageControlUpdateCurrentPageDisplay()

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

    CardPageControl.UpdateCurrentPageDisplay();
}

这将使 PageControl 当前指示器与当前页面同步。


推荐阅读