swiftuicollectionviewimessage-extensionmssticker

CollectonView "readjusts" origin after loaded into view


I am making a custom sticker pack. It is an iMessage Extension app. I am subclassing UICollectionView rather than using the basic MSMessagesViewController. So this happens only when I select the chevron icon in the expanded view to change back to the compact view. What's going on(you can see in the gif below) is the stickers are place in the view and appear to be set in their location, but after a split second, they seem to readjust their positions...Is there something in CollectionView that I should be doing to prevent this?

I'm starting to think it could be a bug, because the header bar that contains the text field, iMessage app drawer icon, heart icon and camera icon seem to be cut-off about the same amount as the shift.

enter image description here

here is the code from github


Solution

  • The problem with your code is that the contentInset for your collectionView in your layout() call is 6 pixel off from the original position. That's why the animation adjusts the 6 pixel after the animation has finished.

    Just change the UIEdgeInsets() in your layout() call inside the StickerCollectionVC to:

    self.collectionView?.contentInset = UIEdgeInsets(   top: screenW * 0.1 - 6,
                                                                left: screenW * 0.1,
                                                                bottom: 20 + (screenW * 0.1),
                                                                right: screenW * 0.1)