Comments (4)
I see, this layout assumes the item size same as collection view size since it’s a paging layout
but you can make smaller views inside your cell,
and by doing that you have more control on sizing, transforms and animations
for instance, you can use auto-layout for sizing
check out this example:
import UIKit
import CollectionViewPagingLayout
class ViewController: UIViewController, UICollectionViewDataSource {
var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
setupCollectionView()
}
private func setupCollectionView() {
collectionView = UICollectionView(frame: view.frame, collectionViewLayout: CollectionViewPagingLayout())
collectionView.isPagingEnabled = true
collectionView.register(MyCell.self, forCellWithReuseIdentifier: "cell")
collectionView.dataSource = self
view.addSubview(collectionView)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
collectionView?.performBatchUpdates({
self.collectionView.collectionViewLayout.invalidateLayout()
})
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
}
}
class MyCell: UICollectionViewCell, ScaleTransformView {
var card: UIView!
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setup()
}
func setup() {
// use AutoLayout in real world
card = UIView(frame: CGRect(x: 80, y: 100, width: frame.width - 160, height: frame.height - 200))
card.backgroundColor = .gray
contentView.addSubview(card)
}
let scaleOptions = ScaleTransformViewOptions(
minScale: 0.6,
scaleRatio: 0.4,
translationRatio: CGPoint(x: 0.66, y: 0.2),
maxTranslationRatio: CGPoint(x: 2, y: 0)
)
}
from collectionviewpaginglayout.
Hi, can you explain more?
what’s the problem? what do you want to do? and what is happening that you don’t expect?
from collectionviewpaginglayout.
I want set size for my collectionView, but method sizeForItemAt
not called, after implemented the library CollectionViewPagingLayout
from collectionviewpaginglayout.
Thanks a lot!)
from collectionviewpaginglayout.
Related Issues (20)
- swiftui ensure currentPage is greater than or equal to zero to prevent Index out of range error HOT 1
- Xcode 13.3 and swift version 5.6 Archiving issue ### HOT 1
- Hello, I encountered a problem with UI debugging or description during the development process HOT 1
- Vertical orientation of items HOT 1
- Suggestion for automatic looping scroll
- RTL support for layout HOT 2
- Using ScrollViewReader
- swiftUI use ScalePageView NavigationBar always showing HOT 12
- Strange SwiftUI navigation behavior when using CollectionViewPagingLayout HOT 1
- 新版为什么仅支持iOS13?? HOT 1
- Start on specific page in ScalePageView HOT 2
- How to handle button click event in cell with ScaleTransformView? HOT 1
- About Mac App HOT 2
- Compile time issue HOT 2
- Where is the LayoutDesigner sample app code hosted? HOT 1
- Question on memory leak HOT 1
- Is support objc?
- How to make the layout vertical instead of horizontal?
- TransformPageView RTL dragging is reversed
- View would blink and scrolling when the list changed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from collectionviewpaginglayout.