久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

禁用 UIPageViewController 彈跳 - Swift

Disable UIPageViewController bouncing - Swift(禁用 UIPageViewController 彈跳 - Swift)
本文介紹了禁用 UIPageViewController 彈跳 - Swift的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我一直在制作一個在 UIViewControllers 之間滾動的示例應(yīng)用程序,但重點是我想在滾動結(jié)束時以及返回第一個 UIViewController<時禁用彈跳效果/代碼>.

I've been making a sample app with scrolling between UIViewControllers but the point is i want to disable the bouncing effect at the end of scrolling and when going back to the first UIViewController.

這是我的代碼:

class PageViewController: UIPageViewController,UIPageViewControllerDataSource, UIPageViewControllerDelegate{

    var index = 0
    var identifiers: NSArray = ["FirstNavigationController", "SecondNavigationController"]
    override func viewDidLoad() {

        self.dataSource = self
        self.delegate = self

        let startingViewController = self.viewControllerAtIndex(self.index)

        let viewControllers: NSArray = [startingViewController]
        self.setViewControllers(viewControllers as [AnyObject], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
    }

    func viewControllerAtIndex(index: Int) -> UINavigationController! {

        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
        //first view controller = firstViewControllers navigation controller
        if index == 0 {

            return storyBoard.instantiateViewControllerWithIdentifier("FirstNavigationController") as! UINavigationController

        }

        //second view controller = secondViewController's navigation controller
        if index == 1 {

            return storyBoard.instantiateViewControllerWithIdentifier("SecondNavigationController") as! UINavigationController
        }

        return nil
    }
    func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {

        let identifier = viewController.restorationIdentifier
        let index = self.identifiers.indexOfObject(identifier!)

        //if the index is the end of the array, return nil since we dont want a view controller after the last one
        if index == identifiers.count - 1 {

            return nil
        }

        //increment the index to get the viewController after the current index
        self.index = self.index + 1
        return self.viewControllerAtIndex(self.index)

    }

    func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {

        let identifier = viewController.restorationIdentifier
        let index = self.identifiers.indexOfObject(identifier!)

        //if the index is 0, return nil since we dont want a view controller before the first one
        if index == 0 {

            return nil
        }

        //decrement the index to get the viewController before the current one
        self.index = self.index - 1
        return self.viewControllerAtIndex(self.index)

    }

}

看看這里:

推薦答案

不知道你能不能.UIPageController 不是很可定制.

I don't know if you can. UIPageController is not very customizable.

就個人而言,當(dāng)我想在 UIViewController 之間滾動時,我更喜歡使用一個簡單的 UIViewController,它是一個容器,里面有一個 UIScrollView.然后我以編程方式在 UIScrollView 的 contentSize 中添加所有控制器.您必須將所有控制器添加為容器的子級.

Personally, when I want to scroll between UIViewController, I prefer using a simple UIViewController, which will be a container, with an UIScrollView in it. Then I add programmatically all the controllers in the contentSize of the UIScrollView. You have to add all the controllers as child of the container.

更新 iOS 9

func setupDetailViewControllers() {
    var previousController: UIViewController?
    for controller in self.controllers {
        addChildViewController(controller)
        addControllerInContentView(controller, previousController: previousController)
        controller.didMoveToParentViewController(self)
        previousController = controller
    }
}

func addControllerInContentView(controller: UIViewController, previousController: UIViewController?) {
    contentView.addSubview(controller.view)
    controller.view.translatesAutoresizingMaskIntoConstraints = false

    // top
    controller.view.topAnchor.constraintEqualToAnchor(contentView.topAnchor).active = true

    // bottom
    controller.view.bottomAnchor.constraintEqualToAnchor(contentView.bottomAnchor).active = true

    // trailing
    trailingContentViewConstraint?.active = false
    trailingContentViewConstraint = controller.view.trailingAnchor.constraintEqualToAnchor(contentView.trailingAnchor)
    trailingContentViewConstraint?.active = true

    // leading
    let leadingAnchor = previousController?.view.trailingAnchor ?? contentView.leadingAnchor
    controller.view.leadingAnchor.constraintEqualToAnchor(leadingAnchor).active = true

    // width
    controller.view.widthAnchor.constraintEqualToAnchor(scrollView.widthAnchor).active = true
}

以前的答案

像這樣:

scrollView 是一個 IBOutlet,它對 ContainerViewController 的每個邊緣都有約束

scrollView is an IBOutlet with contraints to each edge of the ContainerViewController

class ContainerViewController: UIViewController {

@IBOutlet var scrollView: UIScrollView!

override func viewDidLoad() {
    super.viewDidLoad()
    scrollView.bounces = false
    scrollView.pagingEnabled = true
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}

override func viewDidLayoutSubviews() {
    initScrollView()
}

func initScrollView(){
    let viewController1 = storyboard?.instantiateViewControllerWithIdentifier("ViewController1") as! ViewController1

    viewController1.willMoveToParentViewController(self)
    viewController1.view.frame = scrollView.bounds

    let viewController2 = storyboard?.instantiateViewControllerWithIdentifier("ViewController2") as! ViewController2

    viewController2.willMoveToParentViewController(self)
    viewController2.view.frame.size = scrollView.frame.size
    viewController2.view.frame.origin = CGPoint(x: view.frame.width, y: 0)

    scrollView.contentSize = CGSize(width: 2 * scrollView.frame.width, height: scrollView.frame.height)

    scrollView.addSubview(viewController2.view)
    self.addChildViewController(viewController2)
    viewController2.didMoveToParentViewController(self)

    scrollView.addSubview(viewController1.view)
    self.addChildViewController(viewController1)
    viewController1.didMoveToParentViewController(self)
}}

這篇關(guān)于禁用 UIPageViewController 彈跳 - Swift的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設(shè)置滾動視圖內(nèi)容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動滾動)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運行時,使用 iOS 6.0 SDK 并為 iOS 5 Target 構(gòu)建會導(dǎo)致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創(chuàng)建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 伊人网在线视频 | 欧美视频区 | 久久久久久久影院 | 日本一级一片免费视频 | 国产精品欧美精品 | 免费三级黄色片 | 久久亚洲国产 | 国产亚洲视频在线观看 | 性色av一区二区 | 久久久亚洲精品视频 | 在线视频91| 波多野结衣乳巨码无在线观看 | 黄色毛毛片 | 另类ts人妖一区二区三区 | 女同一区二区三区 | 日韩久久久 | 欧美一级特黄视频 | 高h乱l高辣h文短篇h | 人人澡人人爽 | 婷婷六月综合 | 欧美日韩免费一区二区三区 | 四虎影视在线播放 | 久久在线精品 | 日韩一区二区视频在线观看 | 久久精品美女 | 日韩一级在线观看 | 狠狠se| 国产精品视屏 | 亚洲三区在线 | 国产亚洲欧美日韩高清 | 日韩国产在线观看 | 日本美女毛茸茸 | 日韩一区二区三免费高清在线观看 | 成年人午夜视频 | 日日日日干 | av网站免费在线观看 | 亚洲午夜一区 | 天天操天天干天天 | 日韩黄色网址 | 天天操夜夜骑 | 特级西西444www大精品视频 |