Disable UIPageViewController Swipe - Swift

前端 未结 2 984
囚心锁ツ
囚心锁ツ 2021-01-13 02:22

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 UIPageViewCo

2条回答
  •  攒了一身酷
    2021-01-13 02:36

    You can use this extension:

    extension UIPageViewController {
         var isPagingEnabled: Bool {
            get {
               var isEnabled: Bool = true
               for view in view.subviews {
                   if let subView = view as? UIScrollView {
                       isEnabled = subView.isScrollEnabled
                   }
               }
               return isEnabled
           }
           set {
               for view in view.subviews {
                   if let subView = view as? UIScrollView {
                       subView.isScrollEnabled = newValue
                   }
               }
           }
       }    
    }
    

    and call this:

    pageCtrl.isPagingEnabled = false
    

提交回复
热议问题