禁用 UIPageViewController 滑动 - Swift [英] Disable UIPageViewController Swipe - Swift
本文介绍了禁用 UIPageViewController 滑动 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目中,我使用 UIPageViewController 在 5 个子 UIViewController 之间滑动.在某些子视图控制器中,我需要禁用 UIPageViewController 的滑动手势,以便用户滑动时不会更改为其他视图.那么如何禁用子视图控制器的滑动?
In my project i use UIPageViewController to swipe between 5 child UIViewController. In some of child view controller, i need to disable the swipe gesture of the UIPageViewController so when user swipe it not change to other view. So how i can disable the swipe from the child view controller?
感谢帮助..谢谢
推荐答案
在你的页面视图控制器中,添加以下内容
In your page view controller, add following
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
}
在您的子视图控制器中,您可以通过关注来发布通知.
In your child view controller, you can just post notification by following.
NSNotificationCenter.defaultCenter().postNotificationName("enableSwipe", object: nil)
或
NSNotificationCenter.defaultCenter().postNotificationName("disableSwipe", object: nil)
这篇关于禁用 UIPageViewController 滑动 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文