Giter Site home page Giter Site logo

bmoviewpager's Introduction

BMO ViewPager

CI Status Version License Platform

⚠️ The latest version for Swift 3.2 is 3.2.0 ⚠️ (Not Maintained)

⚠️ The latest version for Swift 4.0 is 4.1.3 ⚠️

⚠️ The latest version for Swift 4.2 is 4.2.2 ⚠️

⚠️ The latest version for Swift 5 is 5.2.0 ⚠️

4.1.0 Migrating to 4.2.0

Syntax renaming : NSAttributedStringKey to NSAttributedString.Key

3.2.0 to 4.1.0 Migration

Fix error spelling : interporation to interpolation, if you have access this variable, please change the naming

About

A ViewPager with NavigationBar component based on UIPageViewController and UICollectionView, which is a convenience way to supply and manager each viewController.

I want to make UIPageViewController more intuitive for using it, like UITableView, and supply a navigationBar quickly and simply.

More importantly, when UIPageViewController scroll continuously, pageControl sometimes will get wrong index, this viewPager can help you solve it.

There are some standard dataSource and delegate implemented for generating each page and navigationBar, each of these classes have simple sample code showing in the Pod Example for BmoViewPager.

Simple Usage

Create a UIView extend BmoViewPager

Implement BmoViewPagerDataSource

give page count and each page controller, just like using tableView

func bmoViewPagerDataSourceNumberOfPage(in viewPager: BmoViewPager) -> Int {
    return YourPageCount
}
func bmoViewPagerDataSource(_ viewPager: BmoViewPager, viewControllerForPageAt page: Int) -> UIViewController {
    return YourPageViewController
}

With a NavigationBar

Create a UIView extend BmoViewPagerNavigationBar

Assign a BmoViewPager to the BmoViewPagerNavigationBar

using default style, only need to give the each page title

func bmoViewPagerDataSourceNaviagtionBarItemTitle(_ viewPager: BmoViewPager, navigationBar: BmoViewPagerNavigationBar, forPageListAt page: Int) -> String? {
    return YourPageTitleString
}

navigation item title can custom attributed

func bmoViewPagerDataSourceNaviagtionBarItemNormalAttributed(_ viewPager: BmoViewPager, navigationBar: BmoViewPagerNavigationBar, forPageListAt page: Int) -> [NSAttributedString.Key : Any]? {
    return [
        NSAttributedString.Key.foregroundColor : UIColor.lightGray,
        NSAttributedString.Key.font : UIFont.systemFont(ofSize: 14.0)
    ]
}
func bmoViewPagerDataSourceNaviagtionBarItemHighlightedAttributed(_ viewPager: BmoViewPager, navigationBar: BmoViewPagerNavigationBar, forPageListAt page: Int) -> [NSAttributedString.Key : Any]? {
    return [
        NSAttributedString.Key.foregroundColor : UIColor.red,
        NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 14.0)
    ]
}

if you don't want use default style, you can custom your own background view and highlighted background view

Advanced Usage

Support Right-to-Left (RTL) User Interface

Support Vertical and Horizontal direction scroll

BmoNavigationBar Auto Focus (Default is true)

BmoNavigationBar Title can set normal and highlighted attributed style

BmoViewPager infinitScroll (Default is false)

BmoViewPager presentedPageIndex can programmatically assign the present page

Custom NavigationBar animation, you can get scroll progress from BmoViewPagerDelegate

Navigation bar interpolation animation when change viewPager page by tap navigationItem

InfiniteScroll Custom NavigationBar animation

PageControl Optimized

native pageController have a default pageControl if you implement the func presentationCount(for pageViewController: UIPageViewController) -> Int and func presentationIndex(for pageViewController: UIPageViewController) -> Int but sometimes the index have a little bug, if you feel the way too, hope it help you

Native PageController continuously scroll continuously scroll using bmoViewPager

Popular Issue

How to animate changing pages on BmoViewPager ?

There is a property isInterpolationAnimated in BmoViewPager and BmoViewPagerNavigationBar, default value both true. Most importantly, If you want to have scroll animation every time, the pageViewController need be initialed before BmoViewPagerDataSource ask it. and told BmoViewPager the reference by public func setReferencePageViewController(_ vc: UIViewController, at page: Int)

For example, I always keep the UIViewController of previous page, current page and next page in a dictionary cachedPageViewControllers

var cachedPageViewControllers = [Int: UIViewController]()
func bmoViewPagerDelegate(_ viewPager: BmoViewPager, didAppear viewController: UIViewController, page: Int) {
    switch page {
    case 0:
        self.prepareCachedPageViewControllers(pages: [pageCount - 1, page, page + 1])
    case 1..<(pageCount - 1):
        self.prepareCachedPageViewControllers(pages: [page - 1, page, page + 1])
    case pageCount - 1:
        self.prepareCachedPageViewControllers(pages: [page - 1, page, 0])
    default:
        break
    }
}
func bmoViewPagerDataSource(_ viewPager: BmoViewPager, viewControllerForPageAt page: Int) -> UIViewController {
    if let cacheVC = cachedPageViewControllers[page] {
        return cacheVC
    } else {
        let vc = createPageViewController(page)
        viewPager.setReferencePageViewController(vc, at: page)
        cachedPageViewControllers[page] = vc
        return vc
    }
}
private func prepareCachedPageViewControllers(pages: [Int]) {
    cachedPageViewControllers.forEach({ (key, vc) in
        if !pages.contains(key) {
            cachedPageViewControllers[key] = nil
        }
    })
    pages.forEach { (page) in
        if cachedPageViewController[page] == nil {
            let vc = createPageViewController(page)
            viewPager.setReferencePageViewController(vc, at: page)
            cachedPageViewControllers[page] = vc
        }
    }
}
private func createPageViewController(_ page: Int) -> UIViewController {
    //TODO: return your own UIViewController
}

Be sure to return different UIViewController for every page

Because BmoViewPager is based on UIPageViewController, and when the scroll view scroll to edge, it will ask UIPageViewControllerDataSource to get the next and the previous page. At the same time, BmoViewPager save the view controller and page number in the view controller's view, it will let the this page view controller has wrong property.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 9.0+
  • Swift 5.0+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.0+ is required to build BmoViewPager 4.0.0+.

To integrate BmoViewPager into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!

target '<Your Target Name>' do
    pod 'BmoViewPager', '~> 5.2.0'
end

Then, run the following command:

$ pod install

Manually

If you prefer not to use the dependency managers, you can integrate BmoViewPager into your project manually, just copy the BmoViewPager folder into your project.

Author

LEE ZHE YU, [email protected]

License

BmoViewPager is available under the MIT license. See the LICENSE file for more info.

bmoviewpager's People

Contributors

tzef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bmoviewpager's Issues

IB Designables: Failed to render and update auto layout status

IB Designables: Failed to render and update auto layout status for MainPagerViewController (0OZ-tK-gVb): dlopen(BmoViewPager.framework, 1): no suitable image found. Did find:
BmoViewPager.framework: required code signature missing for 'BmoViewPager.framework'

iOS 11 adjust ContentSize

when I add the BmoViewPagerNavigationBar to nav titleView, pushed a VC then pop back, the pagerBar did disappeared.

so must add the code to BmoViewPagerNavigationBar.

    /// iOS11 navigationItem.titleView
    public override var intrinsicContentSize: CGSize {
        return frame.size
    }

Can't seem to animate changing pages on BmoViewPager

I have a HomeViewController in which I have added a BmoViewPager (not BmoPageViewController). It works fine and I can get the current page when I scroll with the finger, using delegate methods.

But I've found a strange behavior. I cannot seem to change the page in an animated way. I'm implementing my own UIPageControl in which I have a target function this way:

@objc func pageControlDidChangePage(_ pageControl: UIPageControl) {
    pagerView.presentedPageIndex = pageControl.currentPage
}

So when I tap on the UIPageControl, the page should change with it. It does change the page, but that change is not animated. How do I make it animated?

There should be a func setPresentedPage(index: Int, animated: Bool = false) to allow us to animate the change. Or am I missing something?

Thanks!

scrollable has no effect

The property scrollable on the BmoViewPager seems to have no effect.

I want to prevent the user to swipe left and right to change the content. That should be possible only with the BmoViewPagerNavigationBar

Any hints?

RTL Support

Hi,

Thank you for your great pod.
I configured it easily and it worked, you mentioned that it supports RTL but I couldn't find the way to make my view RTL.
I just want to know how can I do this.

Thank you again.

Navigation bar not focus to the current page

If have 10 view controllers. then I select 9th one means, it does't focus current title.

viewPagerNavigationBar.autoFocus = true -> it's support only the page did changed.

help me to fix this.

Pod installation issue

Hello, can you please help me regarding following error.

[!] Unable to find a specification for BmoViewPager (~> 4.0.0)

Animating pages on tapping on navigation pager items

I have view pager with 2 items. For example, when I move to second item with swipe and then back to first with tapping on it's cell item in view pager navigation bar transition to first page is animating. But when I start to tap on cells items without using swipe gestures pager stops animate page changes. Is there a way to animate page changes in any cases?

I am unable to get any delegate method or datasource method inside button action.

I want to achieve like this:

Have to used Next button which ll move the scroller to other index of controller but unable to do so, Kindly help if there is any thing related this.

Here its what i am doing

import UIKit
import BmoViewPager

class ViewController: UIViewController {

@IBOutlet weak var viewPager: BmoViewPager!
@IBOutlet weak var pageControl: UIPageControl!
weak var BmoDelegate: BmoViewPagerDelegate?
weak var BmoDataSource: BmoViewPagerDataSource?

var globalPage = 0
override func viewDidLoad() {
    super.viewDidLoad()
    
    viewPager.delegate = self
    viewPager.dataSource = self
}

@IBAction func actionNext(_ sender: Any) {
    
    if self.globalPage < 3 {
        
        self.globalPage += 1

        BmoDataSource.bmoViewPagerDataSource(_ viewPager: BmoViewPager, viewControllerForPageAt page: Int) -> UIViewController {
            
            self.globalPage = page

            switch self.globalPage {
            
            case 0:
                if let vc = storyboard?.instantiateViewController(withIdentifier: "VC1") as? VC1 {
                    return vc
                }
            case 1:
                if let vc = storyboard?.instantiateViewController(withIdentifier: "VC2") as? VC2 {
                    return vc
                }
            case 2:
                if let vc = storyboard?.instantiateViewController(withIdentifier: "VC3") as? VC3 {
                    return vc
                }
            default:
                break
            }
            return UIViewController()
        }
        
    }
}

}

extension ViewController: BmoViewPagerDataSource {
func bmoViewPagerDataSourceNumberOfPage(in viewPager: BmoViewPager) -> Int {
return 3
}

func bmoViewPagerDataSource(_ viewPager: BmoViewPager, viewControllerForPageAt page: Int) -> UIViewController {
    
    self.globalPage = page

    switch self.globalPage {
    
    case 0:
        if let vc = storyboard?.instantiateViewController(withIdentifier: "VC1") as? VC1 {
            return vc
        }
    case 1:
        if let vc = storyboard?.instantiateViewController(withIdentifier: "VC2") as? VC2 {
            return vc
        }
    case 2:
        if let vc = storyboard?.instantiateViewController(withIdentifier: "VC3") as? VC3 {
            return vc
        }
    default:
        break
    }
    return UIViewController()
}

}

extension ViewController: BmoViewPagerDelegate {

func bmoViewPagerDelegate(_ viewPager: BmoViewPager, pageChanged page: Int) {
    self.globalPage = page
    pageControl.currentPage = self.globalPage
}

}

Customise navigation bar titles names

Hi,

how can I change the title of navigation bar. I need to customise the Title

func bmoViewPagerDataSourceNaviagtionBarItemTitle(_ viewPager: BmoViewPager, navigationBar: BmoViewPagerNavigationBar, forPageListAt page: Int) -> String? {
return "Food (page)"
}

I need to change title based on requirement

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.