Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何检测UIPageViewController';中国的观点已经改变_Swift_Uiviewcontroller_Uipageviewcontroller - Fatal编程技术网

Swift 如何检测UIPageViewController';中国的观点已经改变

Swift 如何检测UIPageViewController';中国的观点已经改变,swift,uiviewcontroller,uipageviewcontroller,Swift,Uiviewcontroller,Uipageviewcontroller,我有一个带有PageViewController的应用程序,我想制作自己的自定义PageViewController指示器。一切都安排好了。我现在需要做的唯一一件事就是弄清楚如何判断视图控制器的视图何时发生了更改,以及它当前在哪个视图上 我已链接到。在第一部分中,我单击顶部的按钮以更改页面和指示当前页面工作的滑块,但在这之后,我用手指滑动以更改控制器,我想让滑块指示器随页面移动。如果您有一组正在显示的页面,则可以使用UIPageViewControllerDelegate检测页面更改。更具体地说

我有一个带有PageViewController的应用程序,我想制作自己的自定义PageViewController指示器。一切都安排好了。我现在需要做的唯一一件事就是弄清楚如何判断视图控制器的视图何时发生了更改,以及它当前在哪个视图上


我已链接到。在第一部分中,我单击顶部的按钮以更改页面和指示当前页面工作的滑块,但在这之后,我用手指滑动以更改控制器,我想让滑块指示器随页面移动。

如果您有一组正在显示的页面,则可以使用UIPageViewControllerDelegate检测页面更改。更具体地说,这是一个函数,因为它将告诉您将要转换到什么。然后,您可以根据即将显示的视图控制器来确定您所处的页面。

这里我已经说明了如何使用PageViewController获取当前页面索引

func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool)
    {
        if (completed)
        {
            //No need as we had Already managed This action in other Delegate
        }
        else
        {
            ///Update Current Index
            Manager.pageindex = Manager.lastIndex

            ///Post notification to hide the draggable Menu
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "updateLabelValue"), object: nil)
        }
    }

    //MARK: Check Transition State
    func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController])
    {
        ///Update Last Index
        Manager.lastIndex = Manager.pageindex

        ///Update Index
        Manager.pageindex = pages.index(of: pendingViewControllers[0])!

        ///Post notification to hide the draggable Menu
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "updateLabelValue"), object: nil)
    }
我使用了Notification Observer通知主控制器页面更改和执行某些操作

Manager是我的结构,它保存当前的页码,您可以在结构或类中随时保存索引

我的结构类

//Struct Class
struct Manager
{
    ///Current Page Index
    static var pageindex :Int = 0

    ///Last Index
    static var lastIndex :Int = 0
}
主要用法

switch Manager.pageindex
        {
        case 0:
            self.mainHomeLabel.text = "VC1"
        case 1:
            self.mainHomeLabel.text = "VC2"
        case 2:
            self.mainHomeLabel.text = "VC3"
        default:
            self.mainHomeLabel.text = "VC1"
        }
注意如果对相应代码有任何疑问,请询问

更新-添加演示项目链接


链接-

非常感谢您的回答,非常感谢。我想我理解你对bud的理解,你能帮我一点实现吗,我把这段代码放在哪个类中?好的,我将与你分享示例项目我已经分享了一个创建的演示项目,请检查一下,这将为你提供所需的所有步骤非常感谢,我做了你说的一切,这是非常直截了当的,但是我的uuuuuuuuuuuuuuuuuuuuuuuuuuufunc页面视图控制器(uuuPageViewController:UIPageViewController,将转换为PendingViewController:[UIViewController])从来没有人打电话给我,我确实有委托人,请让我检查一下