最近我从Android世界切换到iOS.我已经看到了两种创建水平滑块的选项.我的目标是在此图像上创建一个水平的卡片滑块.
我很困惑哪个元素需要iOS中最好的选项.我应该使用CollectionView还是应该使用PageViewController?由于我是初学者,因此我不能在现阶段使用图书馆,因为我的知识有限.请建议我该怎么做
Dan*_*iel 11
您应该使用UICollectionView.
1)使用设置水平布局 UICollectionViewFlowLayout
let layout = UICollectionViewFlowLayout()
// The size of each item. Pick a suitable height so that the items do not get stacked:
layout.itemSize = CGSize(width: view.frame.width / 2, height: view.frame.height)
// The most important part:
layout.scrollDirection = .horizontal
// Then initialize collectionView
let collectionView = UICollectionView(frame: frame, collectionViewLayout: layout)
Run Code Online (Sandbox Code Playgroud)
2)设置缩放(伪代码)
一世.有self实施UIScrollViewDelegate方法scrollViewDidScroll(UIScrollView)
II.组collectionView.delgate = self
III.在scrollViewDidScroll(UIScrollView),通过铸造scrollView as! UICollectionView和获取visibleCells属性获取所有可见单元格.
IV.对于可见细胞中的细胞,在CGAffineTransform给定细胞距离屏幕水平中心的距离处设置适当的比例(细胞内容,而不是细胞本身).这可能需要一些算术; 这应该工作得很好:
s = ?0.00005 * pow(cell.center.x, 2) + 1.5
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!如果需要,请随时要求澄清.
| 归档时间: |
|
| 查看次数: |
15130 次 |
| 最近记录: |