Removing a view controller from UIPageViewController

前端 未结 12 2538
梦谈多话
梦谈多话 2020-11-28 19:22

It\'s odd that there\'s no straightforward way to do this. Consider the following scenario:

  1. You have a page view controller with 1 page.
  2. Add another p
12条回答
  •  悲哀的现实
    2020-11-28 19:51

    For improve this. You should detect whether pageView is scrolling or not before setViewControllers.

    var isScrolling = false
    
    func viewDidLoad() {
    ...
    
      for v in view.subviews{
        if v.isKindOfClass(UIScrollView) {
          (v as! UIScrollView).delegate = self
        }
      }
    }
    
    func scrollViewWillBeginDragging(scrollView: UIScrollView){
        isScrolling = true
    }
    
    func scrollViewDidEndDecelerating(scrollView: UIScrollView){
        isScrolling = false
    }
    
    func jumpToVC{
        if isScrolling {  //you should not jump out when scrolling
            return
        }
        setViewControllers([vc], direction:direction, animated:true, completion:{[unowned self] (succ) -> Void in
            if succ {
                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    self.setViewControllers([vc], direction:direction, animated:false, completion:nil)
                })
            }
        })
    }
    

提交回复
热议问题