ButtonBarPagerTabStripViewController updateIndicator toIndex是错误的

时间:2016-12-07 08:29:10

标签: ios swift xlpagertabstrip

当用户更改屏幕时,我需要在导航栏中添加或删除项目,因此我的代码如下:

override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
    super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
    if indexWasChanged {
        if toIndex == 2 {
            rightBtn.alpha = 1
        } else {
            rightBtn.alpha = 0
        }
    }
}

rightBtn只是导航栏右端的一个按钮。

然而,在我的测试运行期间,我注意到如果用户点击ButtonBar而不是滑动以更改屏幕,则fromIndex和toIndex是错误的。它仍然是最后一次更改的值。 例如。当用户从第三个屏幕滑动到第二个屏幕时,fromIndex将是2和toIndex 1但是如果用户点击条形图上的第三个按钮,则即使预期在1指数toIndex,fromIndex仍然是2即使现在它应该是2,也将保持在1。 这导致我的rightBtn没有显示用户是否从第三个屏幕滑动然后将该条点击回第三个。

有没有办法在这种情况下获得正确的toIndex,还是可以修复?

第一部分是有缺陷的部分,我通过直接点击按钮来导航,第二部分没有指针是导航通过滑动工作正常,图标只是假设出现在第三个选项卡上

1 个答案:

答案 0 :(得分:1)

我已经找到了解决方案,对于有同样问题的人,ButtonBarPagerTabStripViewController中有一个currentIndex。所以这个:

    if indexWasChanged {
        if currentIndex == 2 {
            rightBtn.alpha = 1
        } else {
            rightBtn.alpha = 0
        }
    }

将解决问题中的原始代码。

我也去了GitHub project,发现遇到这个问题的其他人已经报告过了。希望它将被修复,两种方法都可以使用。