Как использовать анимацию слайда, а не анимацию "ореола", когда UICollectionViewCell меняет положение из-за изменения высоты своего родителя?

Я строю UICollectionView, который имеет две ячейки. Когда пользователь нажимает кнопку, вторая ячейка должна переместиться прямо под первой ячейкой прямо справа от первой ячейки (за пределами экрана) и позволить пользователю прокрутить ее.

Кикер в том, что мне нужно, чтобы он появился, чтобы скользить в новую позицию. Используя мой текущий код, это просто "призрак".

Вот как я это делаю сейчас:

  • Инициализируйте UICollectionView с UICollectionViewFlowLayout с горизонтальной прокруткой, включенной подкачкой и высотой двух ячеек с полем (196pt * 2 + 8pt = 400pt)

    func setupTestCollectionView() {
    
        // Create the layout, the frame, and the collection view
    
        let testLayout = UICollectionViewFlowLayout()
        let testFrame = CGRect()
        let collectionView = UICollectionView(frame: testFrame, collectionViewLayout: testLayout)
    
        // Specify the attributes of the elements we just created and add them to the primary view
    
        testLayout.scrollDirection = UICollectionViewScrollDirection.horizontal
        testLayout.minimumLineSpacing = 8
        testLayout.minimumInteritemSpacing = 0
    
        collectionView.translatesAutoresizingMaskIntoConstraints = false
        collectionView.isPagingEnabled = true
        collectionView.clipsToBounds = false
        collectionView.backgroundColor = UIColor.green
        collectionView.register(ArtworkCollectionViewCell.self, forCellWithReuseIdentifier: "artworkCell")
        collectionView.delegate = self
        collectionView.dataSource = self
    
        view.addSubview(collectionView)
    
        // Set all of the constraints to position the UICollectionView in the primary view then append them to the initialConstraints array
    
        let topConstraint = collectionView.topAnchor.constraint(equalTo: view.topAnchor, constant: 8)
        let leadingConstraint = collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0)
        let trailingConstraint = collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0)
        testHeightConstraint = collectionView.heightAnchor.constraint(equalToConstant: 400)
    
        // testHeightConstraint is declared outside of this function so we can modify it in a different funcction when the user taps a button
    
        initialConstraints.append(contentsOf: [topConstraint, leadingConstraint, trailingConstraint, testHeightConstraint])
    
    
    }
    
  • Измените ограничение высоты UICollectionView, когда пользователь нажимает кнопку до высоты 1 ячейки (196pt) и анимирует обновление макета

    func testButtonAction() {
    
        // Change the height constraint of the UICollectionView
    
        testHeightConstraint.constant = 196
    
        // Animate the layout update
    
        UIView.animate(withDuration: 0.2) {
            self.view.layoutIfNeeded()
        }
    
    }
    

Это позволяет добиться нужной мне функции (см. Скриншоты ниже), но до сих пор я не смог понять, как изменить анимацию. Любая помощь в этом с благодарностью!

Заранее спасибо!

Скриншот при загрузке просмотра:

Снимок экрана при загрузке

Снимок экрана после нажатия кнопки:

Снимок экрана после нажатия кнопки

Скриншот прокрутки (чтобы показать функциональность и положение):

Скриншот прокрутки

0 ответов

Другие вопросы по тегам