Я хочу создать прокручиваемое фоновое изображение, подобное этому: https://drive.google.com/file/d/1A8FPnp ... sp=sharing
В этом случае, когда я прокручиваю ячейки представления коллекции, фоновое изображение также прокручивается.
Я использую этот код для создания UICollectionViewCompositionalLayout: StoreViewController
[
{
"index": 1,
"identifier": "carouselCell",
"title": "",
"subtitle": "",
"item": [
{
"index": 1,
"tagline": "Featured",
"name": "Strokey",
"subheading": "You'll never stroke the same way again.",
"image": "Heading1",
"iap": true
},
{
"index": 2,
"tagline": "See it in dark mode",
"name": "Smartwhirl",
"subheading": "People who love whirling just like you!",
"image": "Heading2",
"iap": false
},
{
"index": 3,
"tagline": "New update",
"name": "Professorify",
"subheading": "Introducing your portable professor.",
"image": "Heading3",
"iap": true
},
{
"index": 4,
"tagline": "New update",
"name": "Professorify",
"subheading": "Introducing your portable professor.",
"image": "Heading3",
"iap": true
},
{
"index": 5,
"tagline": "New update",
"name": "Professorify",
"subheading": "Introducing your portable professor.",
"image": "Heading3",
"iap": true
},
{
"index": 6,
"tagline": "New update",
"name": "Professorify",
"subheading": "Introducing your portable professor.",
"image": "Heading3",
"iap": true
},
{
"index": 7,
"tagline": "New update",
"name": "Professorify",
"subheading": "Introducing your portable professor.",
"image": "Heading3",
"iap": true
},
{
"index": 8,
"tagline": "New update",
"name": "Professorify",
"subheading": "Introducing your portable professor.",
"image": "Heading3",
"iap": true
},
{
"index": 9,
"tagline": "New update",
"name": "Professorify",
"subheading": "Introducing your portable professor.",
"image": "Heading3",
"iap": true
},
{
"index": 10,
"tagline": "New update",
"name": "Professorify",
"subheading": "Introducing your portable professor.",
"image": "Heading3",
"iap": true
},
]
},
]
У меня есть этот макет:
Попробую объяснить. Например, у меня iPhone в горизонтальном положении с шириной экрана 932 пикселя. И у меня есть фоновое изображение шириной 1864 пикселей. У меня также есть определенное количество клеток. Я хочу разделить ширину фонового изображения (например, 1864 пикселей) на количество ячеек (например, 10), и когда пользователь прокручивает ячейки, я хочу, чтобы фоновое изображение перемещалось на +186,4 пикселей. вправо или влево в зависимости от направления движения.
А как сделать прокручиваемый фон?
Я хочу создать прокручиваемое фоновое изображение, подобное этому: https://drive.google.com/file/d/1A8FPnpndJskjj-xRye8f1L1_QDSfqHt_/view?usp=sharing В этом случае, когда я прокручиваю ячейки представления коллекции, фоновое изображение также прокручивается. Я использую этот код для создания UICollectionViewCompositionalLayout: [b]StoreViewController[/b] [code] class StoreViewController: UIViewController {
var collectionView: UICollectionView! var dataSource: UICollectionViewDiffableDataSource? let sections = Bundle.main.decode([Section].self, from: "section.json")
required init?(coder: NSCoder) { fatalError("Not happening") } } [/code] [b]Элемент[/b] [code]public struct Item: Decodable, Hashable { let index: Int let tagline: String let name: String let subheading: String let image: String let iap: Bool } [/code] [b]Раздел[/b] [code]public struct Section: Decodable, Hashable { let index: Int let identifier: String let title: String let subtitle: String let item: [Item] } [/code] [b]Пакет[/b] [code]extension Bundle { func decode(_ type: T.Type, from file: String) -> T { guard let url = self.url(forResource: file, withExtension: nil) else { fatalError("Failed to locate \(file) in bundle.") }
guard let data = try? Data(contentsOf: url) else { fatalError("Failed to load \(file) from bundle.") }
let decoder = JSONDecoder()
guard let loaded = try? decoder.decode(T.self, from: data) else { fatalError("Failed to decode \(file) from bundle.") }
return loaded } } [/code] [b]SelfConfiguringCell[/b] [code]protocol SelfConfiguringCell { static var reuseIdentifier: String { get } func configure(with item: Item) } [/code] [b].json[/b] [code][ { "index": 1, "identifier": "carouselCell", "title": "", "subtitle": "", "item": [ { "index": 1, "tagline": "Featured", "name": "Strokey", "subheading": "You'll never stroke the same way again.", "image": "Heading1", "iap": true }, { "index": 2, "tagline": "See it in dark mode", "name": "Smartwhirl", "subheading": "People who love whirling just like you!", "image": "Heading2", "iap": false }, { "index": 3, "tagline": "New update", "name": "Professorify", "subheading": "Introducing your portable professor.", "image": "Heading3", "iap": true }, { "index": 4, "tagline": "New update", "name": "Professorify", "subheading": "Introducing your portable professor.", "image": "Heading3", "iap": true }, { "index": 5, "tagline": "New update", "name": "Professorify", "subheading": "Introducing your portable professor.", "image": "Heading3", "iap": true }, { "index": 6, "tagline": "New update", "name": "Professorify", "subheading": "Introducing your portable professor.", "image": "Heading3", "iap": true }, { "index": 7, "tagline": "New update", "name": "Professorify", "subheading": "Introducing your portable professor.", "image": "Heading3", "iap": true }, { "index": 8, "tagline": "New update", "name": "Professorify", "subheading": "Introducing your portable professor.", "image": "Heading3", "iap": true }, { "index": 9, "tagline": "New update", "name": "Professorify", "subheading": "Introducing your portable professor.", "image": "Heading3", "iap": true }, { "index": 10, "tagline": "New update", "name": "Professorify", "subheading": "Introducing your portable professor.", "image": "Heading3", "iap": true }, ] }, ] [/code] У меня есть этот макет: [img]https://i.sstatic.net/ 0b2J0TrC.png[/img]
Попробую объяснить. Например, у меня iPhone в горизонтальном положении с шириной экрана 932 пикселя. И у меня есть фоновое изображение шириной 1864 пикселей. У меня также есть определенное количество клеток. Я хочу разделить ширину фонового изображения (например, 1864 пикселей) на количество ячеек (например, 10), и когда пользователь прокручивает ячейки, я хочу, чтобы фоновое изображение перемещалось на +186,4 пикселей. вправо или влево в зависимости от направления движения. А как сделать прокручиваемый фон?