如何在禁用SWIFT 2.0中突出显示的按钮延迟后启用PageViewController中的滚动

时间:2016-03-12 08:38:51

标签: swift button scroll

我在UIPageViewController中的按钮突出显示延迟时遇到问题。 我现在可以通过将属性“delaysContentTouches”= false设置为子视图来解决。 但现在我不能再滚动页面了。我搜索论坛,发现可能有帮助的“gestureRecognizers”。但我不知道如何设置。 你能建议我吗?

import UIKit

class PageViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {

    var pages = [UIViewController]()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
        self.dataSource = self

        //declare all pages
        let page1: UIViewController! = storyboard?.instantiateViewControllerWithIdentifier("c01")
        let page2: UIViewController! = storyboard?.instantiateViewControllerWithIdentifier("c02")
        let page3: UIViewController! = storyboard?.instantiateViewControllerWithIdentifier("c03")

        pages.append(page1)
        pages.append(page2)
        pages.append(page3)

        setViewControllers([page1], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
}


    override func viewDidAppear(animated: Bool) {
        for view in self.view.subviews {
            if view is UIScrollView {
                (view as? UIScrollView)!.delaysContentTouches = false
            }
        }
    }



    func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
        guard let viewControllerIndex = pages.indexOf(viewController) else {
            return nil
        }   
        let previousIndex = viewControllerIndex - 1
        guard previousIndex >= 0 else {
            return pages.last
        }  
        guard pages.count > previousIndex else {
            return nil
        } 
        return pages[previousIndex]
    }

    func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
        guard let viewControllerIndex = pages.indexOf(viewController) else {
            return nil
        }        
        let nextIndex = viewControllerIndex + 1
        let orderedViewControllersCount = pages.count
        guard orderedViewControllersCount != nextIndex else {
            return pages.first
        } 
        guard orderedViewControllersCount > nextIndex else {
            return nil
        }    
        return pages[nextIndex]
    }    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

1 个答案:

答案 0 :(得分:0)

我现在可以做到。

uipageviewcontroller是不可能的。 我必须转移到uiscrollviewcontroller 然后将它子类化并覆盖函数touchesShouldCancelInContentView,使我的所有UIButton都为真。

现在我可以毫不拖延地点击按钮,仍然可以用手指滚动。