Disable UIPageViewController Swipe - Swift

丶灬走出姿态 提交于 2019-12-07 08:38:40

问题


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?

Appreciate for help..thanks


回答1:


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)

OR

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


来源:https://stackoverflow.com/questions/38710959/disable-uipageviewcontroller-swipe-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!