mqzhot / zcycleview Goto Github PK
View Code? Open in Web Editor NEW使用UICollectionView实现常见图片无限轮播,支持自定义cell,自定义pageControl,以及轮播样式
License: MIT License
使用UICollectionView实现常见图片无限轮播,支持自定义cell,自定义pageControl,以及轮播样式
License: MIT License
现在pagecontrol即使不需要显示,也会创建
将ZYCycleview设置为tableview的Headerview时,如果tableview下拉时,即tableview的contentoffset为负值时,ZYCycleview会自动滚回第一张图片,是不是scrollview的代理事件冲突了
可不可以把
s.dependency 'Kingfisher', '~> 4.3.1'
改为
s.dependency 'Kingfisher', '>= 4.3.1'
轻触的时候,回滚动画太僵硬,希望作者能调整下
如果在初始化的时候不调用reloadItemsCount,会导致不自动轮播。
比如我是在网络请求后使用的reloadItemsCount
修改了滚动的地方,发现滚动距离总有偏差
发版的时候测了吗。。。。。
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
pageControl.currentPage = getCurrentIndex() % realItemsCount
在未设置itemZoomScale或设置为1时,点击时会发生移位
下载下来 一允许就报错。。。是不是需要配置神马?
正确的写法应该是这样
private func getCurrentIndex() -> Int {
let point = self.convert(collectionView.center, to: self.collectionView)
let indexPath = self.collectionView.indexPathForItem(at: point)
return indexPath?.item ?? 0
}
下载下来 一允许就报错。。。是不是需要配置神马? Value of type 'NSZone' has no member 'common' 这个错误。。而且不仅是这个。很多语法都没通过。。。
在示例二中,如下设置
cycleView2.pageControlIsHidden = true
没有效果,请问如何设置?
试了下,在 scrollView.contentOffset.y
改变时,修改 cycleView
的 frame
,itemSize
,itemZoomScale
都不行呢?
你好,感谢你提供这么好用的第三方库
我在使用过程中有一个需求需要使用自定义cell,所以我添加了相关方法,希望你可以合并进去,使这个库功能更加完善,我pull给你,你可以检查一下,欢迎指证
滑动过半才会滚动到上一页/下一页,如果滑动较快且没有过半,回弹的速率就会很大,显得很突兀,建议加上速率的过滤条件
根本原因在于
override public func layoutSubviews() {
super.layoutSubviews()
setupItems()
}
在这个时机,items可能会为空
修改如下
/// page数量
public var numberOfPages: Int = 0 {
didSet {
setupItems()
}
}
if isAutomatic { startTimer() } 应该放在 setItemsCount() 后边。
pagecontrol无法显示,cell不能使用xib
动态加载数据设置轮播图,一直滚动在第一张。采用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
Whether planned adaptation swift 5?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.