宜昌外贸网站建设优化推广,怎么做电影网站不违法吗,网络科技公司logo,思睿鸿途北京网站建设最近完成的项目需要左上对齐的瀑布流#xff0c;每个格子的尺寸不同#xff0c;可以使用UICollectionView定义不同的尺寸#xff0c;但是CollectionView的格子高度是相同的#xff0c;我想要的是这样 左上对齐分别是0、1、2#xff1b;3、4#xff1b; 当前只能自定义一个…最近完成的项目需要左上对齐的瀑布流每个格子的尺寸不同可以使用UICollectionView定义不同的尺寸但是CollectionView的格子高度是相同的我想要的是这样 左上对齐分别是0、1、23、4 当前只能自定义一个组件来完成需求。
使用UIScrollView来复用格子
注册格子类型 public func register(_ viewClass: WidgetCollectionCell.Type?, forViewWithReuseIdentifier identifier: String) {registers[identifier] viewClass}提取格子 public func dequeueReusableView(withReuseIdentifier identifier: String, for index: Int) - WidgetCollectionCell? {var cell: WidgetCollectionCell?let reuseIdentifier \(identifier)_\(index)if let reuseCell outOfScreens[reuseIdentifier] {cell reuseCell}if let viewClass registers[identifier] as? WidgetCollectionCell.Type {cell viewClass.init(reuseIdentifier: identifier, index: index)}if let _ cell {onScreens[reuseIdentifier] celloutOfScreens.removeValue(forKey: reuseIdentifier)}return cell}移除不显示的格子 var screenFrame scrollView.boundsscreenFrame.origin scrollView.contentOffsetallScreens.forEach { v inlet reuseIdentifier \(String(describing: v.reuseIdentifier))_\(v.index)if CGRectIntersectsRect(v.frame, screenFrame) {onScreens[reuseIdentifier] voutOfScreens.removeValue(forKey: reuseIdentifier)addSubview(v)}else {onScreens.removeValue(forKey: reuseIdentifier)outOfScreens[reuseIdentifier] vv.removeFromSuperview()}}兼容原本的UIScrollViewDelegate if let d delegate as? WidgetCollectionViewDelegate {widgetDelegate ddelegate self}然后就是布局了
上传至GitHub
github上创建lib WidgetCollection-Swift 本地创建lib cd 到指定文件夹 pod lib create WidgetCollection-Swift 按提示输入相应内容 将创建好的lib上传WidgetCollection-Swift
pod WidgetCollection-Swift, :git https://github.com/KevinSnoopy/WidgetCollection-Swift.git