swift - 如何在 UIPageViewController 上禁用向左/向右滚动?

标签 swift uipageviewcontroller

我整天都在研究这个,有很多关于这个的帖子,但我还没找到对我有帮助的!

我有一个显示两个 View 的 UIPageViewController(它不是 Root View )。

基本上,当我从 UIPageViewController 中的其中一个 View 添加函数时,我希望能够禁用滚动...?

这有可能吗?!

非常感谢任何提供帮助的人!

最佳答案

刚刚找到解决方案!

在您的页面 View Controller 中,添加以下内容

    override func viewDidLoad(){
        super.viewDidLoad()
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(yourpageviewcontroller.enableSwipe(_:)), name:"enableSwipe", object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(yourpageviewcontroller.disableSwipe(_:)), name:"disableSwipe", object: nil)

    }
    func disableSwipe(notification: NSNotification){
        self.dataSource = nil
    }

func enableSwipe(notification: NSNotification){
    self.dataSource = self
}

在您的 subview Controller 中,您可以通过关注发布通知。

NSNotificationCenter.defaultCenter().postNotificationName("enableSwipe", object: nil)

NSNotificationCenter.defaultCenter().postNotificationName("disableSwipe", object: nil)

关于swift - 如何在 UIPageViewController 上禁用向左/向右滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39877231/

相关文章:

swift - 如何使用 Steam swift 获取 url 的 html?

macos - 如何使用 swift 在窗口中拖动 ImageView (OS X 不是 IOS)

ios - 使用 Alamofire 在 Swift 中下载和解析 json

ios - 通过主视图 Controller 与 UICollectionViewCell 中的按钮交互

ios - 为什么我在运行 PageViewController 后会收到此错误?

ios - 由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因 : 'Duplicate states in queue'

swift - 安装 Cocoapods 报错

ios - 如何使用自动布局在 UIPageViewController 中定位 subview ?

ios - RKSwipeBetweenViewControllers ,没有声明为 Root View Controller

ios - 如何在 iOS 中自动滚动页面 View Controller ?