Git Product home page Git Product logo

zybannerview's Introduction

CocoaPods  CocoaPods  Support 

ZYBannerView

  • 简单易用的轮播控件, 基于UICollectionView实现.

Features

  • 显示的内容可高度自定义
  • 可配置循环滚动效果
  • 可配置是否自动滚动, 以及自动滚动时间间隔
  • 显示\隐藏Footer
  • 自定义PageControl属性
  • 支持在Storyboard\xib中创建并配置其属性
  • 支持Autolayout

Usage

Basic Usage

只需简单的2步即可快速集成此控件

1.创建Banner并设置数据源

self.banner = [[ZYBannerView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
self.banner.dataSource = self;
[self.view addSubview:self.banner];

2.实现数据源方法

// 返回Banner需要显示Item(View)的个数
- (NSInteger)numberOfItemsInBanner:(ZYBannerView *)banner
{
    return 3;
}

// 返回Banner在不同的index所要显示的View
- (UIView *)banner:(ZYBannerView *)banner viewForItemAtIndex:(NSInteger)index
{
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"xxx"]];
    return imageView;
}

Advanced Usage

各种属性与方法的介绍

Property

  • 是否需要循环滚动, 默认为NO
@property (nonatomic, assign) IBInspectable BOOL shouldLoop;
  • 是否显示Footer, 默认为NO (此属性为YES时, shouldLoop属性会被置为NO)
@property (nonatomic, assign) IBInspectable BOOL showFooter;
  • 是否自动滑动, 默认为NO
@property (nonatomic, assign) IBInspectable BOOL autoScroll;
  • 自动滑动间隔时间(s), 默认为 3.0
@property (nonatomic, assign) IBInspectable NSTimeInterval scrollInterval;
  • Banner上显示的PageControl, 可自由配置其属性, 例如pageIndicatorTintColor, currentPageIndicatorTintColor
@property (nonatomic, strong, readonly) UIPageControl *pageControl;
  • 根据需要设置PageControl的frame, 若不设置或者设置为CGRectZero, 则使用默认位置
@property (nonatomic, assign, readwrite)  CGRect pageControlFrame;
  • 数据源与代理
@property (nonatomic, weak) IBOutlet id<ZYBannerViewDataSource> dataSource;
@property (nonatomic, weak) IBOutlet id<ZYBannerViewDelegate> delegate;

NOTE : shouldLoop, showFooter, autoScroll, scrollInterval, dataSource, delegate 均可支持在Storyboard\xib中直接设置

Method

  • 刷新Banner的数据
- (void)reloadData;
  • 开始/停止用于自动滚动的定时器. 比如可以在viewWillAppear:viewWillDisappear:中分别调用这两个方法, 使得Banner没有显示的时候定时器不会一直占用着资源.
- (void)startTimer;
- (void)stopTimer;

DataSource

  • 返回Banner需要显示Item(View)的个数 【required】
- (NSInteger)numberOfItemsInBanner:(ZYBannerView *)banner;
  • 返回Banner在不同的index所要显示的View. 这个View可以是简单的一个UIImageView, 也可以是自定义的一个复杂的View. View的大小自动布局为Banner的大小, 无需对此View设置frame 【required】
- (UIView *)banner:(ZYBannerView *)banner viewForItemAtIndex:(NSInteger)index;
  • 返回Footer在不同状态下(ZYBannerFooterStateIdle正常状态 \ ZYBannerFooterStateTrigger触发状态)显示的文字【optional】
- (NSString *)banner:(ZYBannerView *)banner titleForFooterWithState:(ZYBannerFooterState)footerState;

Delegate

  • 当用户点击了第index个Item时, 此代理方法将被调用 【optional】
- (void)banner:(ZYBannerView *)banner didSelectItemAtIndex:(NSInteger)index;
  • 当用户拖动Footer并达到触发点时, 此代理方法将被调用【optional】
- (void)bannerFooterDidTrigger:(ZYBannerView *)banner;

Requirements

  • iOS 7.0+
  • Xcode 5.0+

Installation

1.使用CocoaPods:

pod 'ZYBannerView'

2.手动添加:

  • 将ZYBannerView文件夹中拖拽到项目中
  • 导入头文件:#import "ZYBannerView.h"

License

ZYBannerView is released under the MIT license. See LICENSE for details.

ZYBannerView in C#

Looking to incorporate ZYBannerView into your project in Xamarin? Check out ZYBannerView_Xamarin (thanks to jingliancui).

zybannerview's People

Contributors

renshu16 avatar zzyspace 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zybannerview's Issues

手动滚动时的问题

@zzyspace 很实用的库。。。感谢
有个小问题想请教一下,在小屏幕设备上iPhone 4s ,iPhone5真机和模拟器,shouldLoop,autoScroll都为YES时,在手动滚动的时候,滚动结束时会有一个很慢的减速效果。

banner不在window上的话pageControl会有问题

您好,我发现如果点击某一张banner弹出一个窗口遮住当前view controller的话,

  • (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
    就不会被调用到了,但是collectionView还是在定时滚动的,这样当你回到banner所在的view controller时会出现page control和页面对不上的关系,要等自动滑倒下一张时才会修正过来。

数据源方法不会创建大量临时view?

// 返回 Banner 在不同的 index 所要显示的 View (可以是完全自定义的v iew, 且无需设置 frame)
- (UIView *)banner:(ZYBannerView *)banner viewForItemAtIndex:(NSInteger)index
{
    // 取出数据
    NSString *imageName = self.dataArray[index];
    
    // 创建将要显示控件
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:imageName];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    
    return imageView;
}

每次调用这个数据源方法就会产生一个临时的View(imageView),这样是不是有什么好的方法避免?

改变item的大小

你好 我通过flowlayout 来改变 itemSize 然后foot view 就失效了 请问可以改变 item的大小吗

banner滑动一周后图片空白问题

你好作者,好久没联系,我是那个把你库转成C#用的人。
今天在调试你的库的时候发现了这个问题。
自己手写的demo没有问题:
数据源是直接手写的集合,集合的元素是局部变量,局部变量也是手写3个,然后添加到集合。

然后出问题的是动态加载的集合:
1 请求webapi获取到数据集 这里ok
2 循环1的集合的时候,在循环内部生成数据源的元素,并把元素添加到类的私有集合字段
3设置banner的数据源为那个私有集合字段
结果运行的时候,第一次显示正常,滚动一周之后,变为空白,到继续留意滚动,会发现图片是一闪而过。

在 UITableView 中使用会卡顿。

在 UITableView 中使用时,当轮播的控件被滑出屏幕再滑回来的时候会产生卡顿,因为 BannerView 又要重新初始构造化一次,有什么解决方案吗?谢谢。

两个小建议

  1. scrollInterval 属性并不能在 Interface Builder 中设计,是否不应该使用 NSTimeInterval
  2. Collection View 一开始只能右划不能左划

内存释放

当控件从父视图移除的时候,需要将定时器停止,否则对象释放不了

view的位置在frame改变时会很奇怪

例如ZYBannerView.m的78行
if (CGRectEqualToRect(self.pageControl.frame, CGRectZero)) { // 若未对pageControl设置过frame, 则使用以下默认frame
在frame改变时 pageControl的位置不会跟随变化
updateSubviewsFrame函数中也没用对collection view的frame进行刷新
是否意味着这个程序并不是很好地支持autolayout?

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.