JoniVR/VerticalCardSwiper

Refresh Card View on view resize

mohit196 opened this issue · 7 comments

New Issue Checklist

Issue Description

Right now If I am resizing the cardView the card cells are not adjusting to the new frame.

Steps:

  • Create a cardView Height constraint
  • Assign a new value to height constraint. -- (Cell will not update its frame)

on reloading the CardView it is still giving me some random behavior because of the previous collection view height.

Environment

  • iOS Version: 12.0
  • Device(s): iPhone XR Simulator
  • Xcode Version: 10.2
  • Create a cardView Height constraint

Do you mean creating height constraints for objects inside the cardView?
I would need some clarification on where exactly you are adding a constraint.
A demo project would be even better.

Are you using the sizeForItem delegate function?
Because that function is meant to allow you to change card sizes.

I added an NSLayoutConstraint on cardSwiper view height and in didSwipeCardAway, I am updating the height constraint. After updating the cell should opt to new constraints.

I have made some changes to the existing project.

VerticalCardSwiper-master-2.zip

So are you saying that the cards don't adapt their size right away once you swipe one away for the first time?

So does adding the following line:

cardSwiper.verticalCardSwiperView.layoutIfNeeded()

below the line where you update the constraint (kind of) fix it for you? (just so I understand what you're talking about)

Thanks for update Joni

Use Case:

  • Swipe 2-3 cards upward.
  • Now Swipe away the topmost card, you will see the issue.

Simulator Screen Shot - iPhone XR - 2019-04-03 at 11 24 32

Yes, I see it now, alright I'll look into what's causing this sometime when I get the time for it.
If you find a solution yourself in the meantime, feel free to post it here or submit a Pull Request.

Hi @mohit196

Quick question, did you try my previous solution?

If I call cardSwiper.layoutIfNeeded() after changing the constraint value it looks like it works to me?

func didSwipeCardAway(card: CardCell, index: Int, swipeDirection: SwipeDirection) {
    cardViewHeightConstraint.constant = 600.0
    cardViewHeightConstraint.priority = .required
    cardSwiper.layoutIfNeeded()
}

VerticalCardSwiper-master-2.zip

Yes, and the issue still exists.

I tried:
cardSwiper.layoutIfNeeded()
and
cardSwiper.verticalCardSwiperView.layoutIfNeeded()