我整天都在研究这个,有很多关于这个的帖子,但我还没找到对我有帮助的!
我有一个显示两个 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/