Giter Club home page Giter Club logo

zcycleview's Introduction

ZCycleView

使用UICollectionView实现常见图片轮播,支持自定义pageControl,自定义Cell

使用方法

let cycleView = ZCycleView()
cycleView.delegate = self
cycleView.reloadItemsCount(images.count)
cycleView.itemSpacing = 10
cycleView.itemSize = CGSize(width: width - 150, height: (width - 150) / 2.3333)
cycleView.initialIndex = 1
view.addSubview(cycleView)

代理方法

protocol ZCycleViewProtocol: class {
    /// 注册cell,[重用标志符:cell类]
    func cycleViewRegisterCellClasses() -> [String: AnyClass]
    /// 配置cell
    func cycleViewConfigureCell(collectionView: UICollectionView, cellForItemAt indexPath: IndexPath, realIndex: Int) -> UICollectionViewCell
    /// 开始拖拽
    func cycleViewBeginDragingIndex(_ cycleView: ZCycleView, index: Int)
    /// 滚动到index
    func cycleViewDidScrollToIndex(_ cycleView: ZCycleView, index: Int)
    /// 点击了index
    func cycleViewDidSelectedIndex(_ cycleView: ZCycleView, index: Int)
    /// 自定义pageControl
    func cycleViewConfigurePageControl(_ cycleView: ZCycleView, pageControl: ZPageControl)
}

zcycleview's People

Contributors

imazy avatar leeyz avatar moshiwu avatar mqzhot 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

zcycleview's Issues

10

下载下来 一允许就报错。。。是不是需要配置神马? Value of type 'NSZone' has no member 'common' 这个错误。。而且不仅是这个。很多语法都没通过。。。

自定义cell功能

你好,感谢你提供这么好用的第三方库
我在使用过程中有一个需求需要使用自定义cell,所以我添加了相关方法,希望你可以合并进去,使这个库功能更加完善,我pull给你,你可以检查一下,欢迎指证

getCurrentIndex 方法 在阿语环境下就 无法实现了

正确的写法应该是这样
private func getCurrentIndex() -> Int {
let point = self.convert(collectionView.center, to: self.collectionView)
let indexPath = self.collectionView.indexPathForItem(at: point)
return indexPath?.item ?? 0
}

master代码运行时产生 collectionView cell 注册问题

Xcode 9.4.1
模拟器: iPhone X

运行 demo:

2018-08-28 15:46:58.230288+0800 ZCycleView[45816:1050740] *** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.54.4/UICollectionView.m:5283
2018-08-28 15:46:58.238403+0800 ZCycleView[45816:1050740] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier ZCycleViewCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(
	0   CoreFoundation                      0x00000001016641e6 __exceptionPreprocess + 294
	1   libobjc.A.dylib                     0x0000000100cf9031 objc_exception_throw + 48
	2   CoreFoundation                      0x0000000101669472 +[NSException raise:format:arguments:] + 98
	3   Foundation                          0x000000010079c652 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
	4   UIKit                               0x0000000102ccfcc0 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 2475
	5   UIKit                               0x0000000102ccff4e -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:] + 169
	6   ZCycleView                          0x000000010026454d _T010ZCycleViewAAC010collectionB0So012UICollectionB4CellCSo0dB0C_10Foundation9IndexPathV13cellForItemAttF + 253
	7   ZCycleView                          0x00000001002664bc _T010ZCycleViewAAC010collectionB0So012UICollectionB4CellCSo0dB0C_10Foundation9IndexPathV13cellForItemAttFTo + 92
	8   UIKit                               0x0000000102cb9756 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 295
	9   UIKit                               0x0000000102cb9629 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 35
	10  UIKit                               0x0000000102cbe8ae -[UICollectionView _updateVisibleCellsNow:] + 4505
	11  UIKit                               0x0000000102cc4688 -[UICollectionView layoutSubviews] + 364
	12  UIKit                               0x00000001022c57a8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1515
	13  QuartzCore                          0x00000001062b3456 -[CALayer layoutSublayers] + 177
	14  QuartzCore                          0x00000001062b7667 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395
	15  UIKit                               0x00000001022af62d -[UIView(Hierarchy) layoutBelowIfNeeded] + 662
	16  UIKit                               0x00000001023e10d0 -[UINavigationController _layoutViewController:] + 1691
	17  UIKit                               0x00000001023daa3a -[UINavigationController _layoutTopViewController] + 231
	18  UIKit                               0x00000001023d8c91 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 731
	19  UIKit                               0x0000000102754db1 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 421
	20  UIKit                               0x0000000102755072 -[UINavigationTransitionView _cleanupTransition] + 605
	21  UIKit                               0x000000010228aea9 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 343
	22  UIKit                               0x0000000102286546 +[UIViewAnimationState popAnimationState] + 319
	23  UIKit                               0x0000000102754b20 -[UINavigationTransitionView transition:fromView:toView:] + 2571
	24  UIKit                               0x00000001023e211f -[UINavigationController _startTransition:fromViewController:toViewController:] + 3261
	25  UIKit                               0x00000001023e261e -[UINavigationController _startDeferredTransitionIfNeeded:] + 870
	26  UIKit                               0x00000001023e386c -[UINavigationController __viewWillLayoutSubviews] + 150
	27  UIKit                               0x000000010263bd0b -[UILayoutContainerView layoutSubviews] + 231
	28  UIKit                               0x00000001022c57a8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1515
	29  QuartzCore                          0x00000001062b3456 -[CALayer layoutSublayers] + 177
	30  QuartzCore                          0x00000001062b7667 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395
	31  QuartzCore                          0x000000010623e0fb _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 343
	32  QuartzCore                          0x000000010626b79c _ZN2CA11Transaction6commitEv + 568
	33  UIKit                               0x0000000102210269 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 141
	34  CoreFoundation                      0x0000000101606b0c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
	35  CoreFoundation                      0x00000001015eb2db __CFRunLoopDoBlocks + 331
	36  CoreFoundation                      0x00000001015eaa84 __CFRunLoopRun + 1284
	37  CoreFoundation                      0x00000001015ea30b CFRunLoopRunSpecific + 635
	38  GraphicsServices                    0x0000000109b61a73 GSEventRunModal + 62
	39  UIKit                               0x00000001021f6057 UIApplicationMain + 159
	40  ZCycleView                          0x0000000100252807 main + 55
	41  libdyld.dylib                       0x0000000107215955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

10

下载下来 一允许就报错。。。是不是需要配置神马?

点击bug

在未设置itemZoomScale或设置为1时,点击时会发生移位

ZPageControl在有些场景会不显示

根本原因在于
override public func layoutSubviews() {
super.layoutSubviews()
setupItems()
}
在这个时机,items可能会为空
修改如下
/// page数量
public var numberOfPages: Int = 0 {
didSet {
setupItems()
}
}

动态加载轮播图,一直在第一张

动态加载数据设置轮播图,一直滚动在第一张。采用snapkit布局
fileprivate func currentIndex() -> Int {
let itemWH = scrollDirection == .horizontal ? flowLayout.itemSize.width+itemSpacing : flowLayout.itemSize.height+itemSpacing
let offsetXY = scrollDirection == .horizontal ? collectionView.contentOffset.x : collectionView.contentOffset.y
// contentOffset changes /(ㄒoㄒ)/~~ ??????????
if itemWH == 0 { return 0 }
let index = round(offsetXY / itemWH)
return Int(index)
}
这段代码返回的一直是0

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.