UICollectionView animating cell beyond boundsHow do I animate constraint changes?UICollectionVIew: Animate cells as they scroll inUsing Auto Layout in UITableView for dynamic cell layouts & variable row heightsHow to track movement of a cell in UICollectionView after screen rotationAnimate UICollectionView cell size change and reposition surrounding cellsScroll UITableView Cell beyond table boundsUICollectionView: animating an in-cell animationResize UICollectionView bounds to fit the cells using Storyboard + Auto LayoutLayout & cell issues when animating UICollectionView frame

If the UK Gov. has authority to cancel article 50 notification, why do they have to agree an extension with the EU

Is there an in-universe explanation given to the senior Imperial Navy Officers as to why Darth Vader serves Emperor Palpatine?

Why did Starhopper's exhaust plume become brighter just before landing?

What is the name of this plot that has rows with two connected dots?

Get contents before a colon

Template factorial function without template specialization

How could a self contained organic body propel itself in space

Coupling two 15 Amp circuit breaker for 20 Amp

Journal published a paper, ignoring my objections as a referee

Spicing up a moment of peace

Why is there not a willingness from the world to step in between Pakistan and India?

Does Mirrorwing Dragon's ability trigger when redirects are involved?

Why does a sticker slowly peel off, but if it is pulled quickly it tears?

In Endgame, wouldn't Stark have remembered Hulk busting out of the stairwell?

How to prevent a hosting company from accessing a VM's encryption keys?

How do Barton (Hawkeye/Ronin) and Romanov (Black Widow) end up on the Benatar on Morag in 2014?

Do multi-engine jets need all engines with equal age to reduce asymmetry in thrust and fuel consumption arising out of deterioration?

Why nature prefers simultaneous events?

Why is "I let him to sleep" incorrect (or is it)?

Why does this London Underground poster from 1924 have a Star of David atop a Christmas tree?

What should be done with the carbon when using magic to get oxygen from carbon dioxide?

What's the point of fighting monsters in Zelda BotW?

STM32 cannot reach individual registers and pins as PIC

Printing a list as "a, b, c." using Python



UICollectionView animating cell beyond bounds


How do I animate constraint changes?UICollectionVIew: Animate cells as they scroll inUsing Auto Layout in UITableView for dynamic cell layouts & variable row heightsHow to track movement of a cell in UICollectionView after screen rotationAnimate UICollectionView cell size change and reposition surrounding cellsScroll UITableView Cell beyond table boundsUICollectionView: animating an in-cell animationResize UICollectionView bounds to fit the cells using Storyboard + Auto LayoutLayout & cell issues when animating UICollectionView frame






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








7















I set up a UICollectionView that has a following settings:



  • collectionView fits screen bounds

  • only vertical scroll is applied

  • most of cells fit to content's width

  • some of cells can change their heights on user interaction dynamically (animated)

It's pretty much like a UITableView, which works fine in most cases, except one specific situation when the animation doesn't apply.



Among stacked cells in collectionView, say one of the upper cells expands its height. Then the lower cell must be moving downwards to keep the distance. If this moving cell's target frame is out of collectionView's bounds, then no animation applies and the cell disappears.



Opposite case works the same way; if the lower cell's source frame is out of screen bounds (currently outside of the bounds) and the upper cell should shrink, no animation applies and it just appear on target frame.



This seems appropriate in memory management logic controlled by UICollectionView, but at the same time nothing natural to show users that some of contents just appear or disappear out of blue. I had tested this with UITableView and the same thing happens.



Is there a workaround for this issue?










share|improve this question


























  • Are you invalidating the collection view layout's context each time?

    – NRitH
    Nov 21 '16 at 3:24











  • @NRitH In fact, that is right. Can that be the reason for the issues?

    – Tack-Gyu Lee
    Nov 21 '16 at 4:16











  • @NRitH After invalidating the layout, I usually call setCollectionViewLayout:animated: to animate the frame changes.

    – Tack-Gyu Lee
    Nov 21 '16 at 4:18











  • @Tack-GyuLee can you please add some code and a gif

    – MCMatan
    Mar 28 at 17:31

















7















I set up a UICollectionView that has a following settings:



  • collectionView fits screen bounds

  • only vertical scroll is applied

  • most of cells fit to content's width

  • some of cells can change their heights on user interaction dynamically (animated)

It's pretty much like a UITableView, which works fine in most cases, except one specific situation when the animation doesn't apply.



Among stacked cells in collectionView, say one of the upper cells expands its height. Then the lower cell must be moving downwards to keep the distance. If this moving cell's target frame is out of collectionView's bounds, then no animation applies and the cell disappears.



Opposite case works the same way; if the lower cell's source frame is out of screen bounds (currently outside of the bounds) and the upper cell should shrink, no animation applies and it just appear on target frame.



This seems appropriate in memory management logic controlled by UICollectionView, but at the same time nothing natural to show users that some of contents just appear or disappear out of blue. I had tested this with UITableView and the same thing happens.



Is there a workaround for this issue?










share|improve this question


























  • Are you invalidating the collection view layout's context each time?

    – NRitH
    Nov 21 '16 at 3:24











  • @NRitH In fact, that is right. Can that be the reason for the issues?

    – Tack-Gyu Lee
    Nov 21 '16 at 4:16











  • @NRitH After invalidating the layout, I usually call setCollectionViewLayout:animated: to animate the frame changes.

    – Tack-Gyu Lee
    Nov 21 '16 at 4:18











  • @Tack-GyuLee can you please add some code and a gif

    – MCMatan
    Mar 28 at 17:31













7












7








7








I set up a UICollectionView that has a following settings:



  • collectionView fits screen bounds

  • only vertical scroll is applied

  • most of cells fit to content's width

  • some of cells can change their heights on user interaction dynamically (animated)

It's pretty much like a UITableView, which works fine in most cases, except one specific situation when the animation doesn't apply.



Among stacked cells in collectionView, say one of the upper cells expands its height. Then the lower cell must be moving downwards to keep the distance. If this moving cell's target frame is out of collectionView's bounds, then no animation applies and the cell disappears.



Opposite case works the same way; if the lower cell's source frame is out of screen bounds (currently outside of the bounds) and the upper cell should shrink, no animation applies and it just appear on target frame.



This seems appropriate in memory management logic controlled by UICollectionView, but at the same time nothing natural to show users that some of contents just appear or disappear out of blue. I had tested this with UITableView and the same thing happens.



Is there a workaround for this issue?










share|improve this question
















I set up a UICollectionView that has a following settings:



  • collectionView fits screen bounds

  • only vertical scroll is applied

  • most of cells fit to content's width

  • some of cells can change their heights on user interaction dynamically (animated)

It's pretty much like a UITableView, which works fine in most cases, except one specific situation when the animation doesn't apply.



Among stacked cells in collectionView, say one of the upper cells expands its height. Then the lower cell must be moving downwards to keep the distance. If this moving cell's target frame is out of collectionView's bounds, then no animation applies and the cell disappears.



Opposite case works the same way; if the lower cell's source frame is out of screen bounds (currently outside of the bounds) and the upper cell should shrink, no animation applies and it just appear on target frame.



This seems appropriate in memory management logic controlled by UICollectionView, but at the same time nothing natural to show users that some of contents just appear or disappear out of blue. I had tested this with UITableView and the same thing happens.



Is there a workaround for this issue?







ios animation uicollectionview uicollectionviewcell uicollectionviewlayout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 11:42









Kathiresan Murugan

1,2801 gold badge9 silver badges28 bronze badges




1,2801 gold badge9 silver badges28 bronze badges










asked Nov 21 '16 at 2:32









Tack-Gyu LeeTack-Gyu Lee

2032 silver badges9 bronze badges




2032 silver badges9 bronze badges















  • Are you invalidating the collection view layout's context each time?

    – NRitH
    Nov 21 '16 at 3:24











  • @NRitH In fact, that is right. Can that be the reason for the issues?

    – Tack-Gyu Lee
    Nov 21 '16 at 4:16











  • @NRitH After invalidating the layout, I usually call setCollectionViewLayout:animated: to animate the frame changes.

    – Tack-Gyu Lee
    Nov 21 '16 at 4:18











  • @Tack-GyuLee can you please add some code and a gif

    – MCMatan
    Mar 28 at 17:31

















  • Are you invalidating the collection view layout's context each time?

    – NRitH
    Nov 21 '16 at 3:24











  • @NRitH In fact, that is right. Can that be the reason for the issues?

    – Tack-Gyu Lee
    Nov 21 '16 at 4:16











  • @NRitH After invalidating the layout, I usually call setCollectionViewLayout:animated: to animate the frame changes.

    – Tack-Gyu Lee
    Nov 21 '16 at 4:18











  • @Tack-GyuLee can you please add some code and a gif

    – MCMatan
    Mar 28 at 17:31
















Are you invalidating the collection view layout's context each time?

– NRitH
Nov 21 '16 at 3:24





Are you invalidating the collection view layout's context each time?

– NRitH
Nov 21 '16 at 3:24













@NRitH In fact, that is right. Can that be the reason for the issues?

– Tack-Gyu Lee
Nov 21 '16 at 4:16





@NRitH In fact, that is right. Can that be the reason for the issues?

– Tack-Gyu Lee
Nov 21 '16 at 4:16













@NRitH After invalidating the layout, I usually call setCollectionViewLayout:animated: to animate the frame changes.

– Tack-Gyu Lee
Nov 21 '16 at 4:18





@NRitH After invalidating the layout, I usually call setCollectionViewLayout:animated: to animate the frame changes.

– Tack-Gyu Lee
Nov 21 '16 at 4:18













@Tack-GyuLee can you please add some code and a gif

– MCMatan
Mar 28 at 17:31





@Tack-GyuLee can you please add some code and a gif

– MCMatan
Mar 28 at 17:31












1 Answer
1






active

oldest

votes


















5







+500








You should add some code or at least a gif of your UI problem.



I tried to replicate your problem using a basic UICollectionViewLayout subclass :



protocol CollectionViewLayoutDelegate: AnyObject 
func heightForItem(at indexPath: IndexPath) -> CGFloat


class CollectionViewLayout: UICollectionViewLayout
weak var delegate: CollectionViewLayoutDelegate?

private var itemAttributes: [UICollectionViewLayoutAttributes] = []

override func prepare()
super.prepare()
itemAttributes = generateItemAttributes()


override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint
return collectionView?.contentOffset ?? .zero
return super.targetContentOffset(forProposedContentOffset: proposedContentOffset)


override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?
return itemAttributes.first $0.indexPath == indexPath


override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?
return itemAttributes.filter $0.frame.intersects(rect)


private func generateItemAttributes() -> [UICollectionViewLayoutAttributes]
var offset: CGFloat = 0
return (0..<numberOfItems()).map index in
let indexPath = IndexPath(item: index, section: 0)
let frame = CGRect(
x: 0,
y: offset,
width: collectionView?.bounds.width ?? 0,
height: delegate?.heightForItem(at: indexPath) ?? 0
)
offset = frame.maxY
let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
attributes.frame = frame
return attributes





In a simple UIViewController, I reloaded the first cell each time a cell is selected:



func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
updatedIndexPath = IndexPath(item: 0, section: 0)
collectionView.reloadItems(at: [updatedIndexPath])



In that case, I faced an animation like this:



bug



How to fix it ?



I think you could try to tweak the attributes returned by super.finalLayoutAttributesForDisappearingItem(at: itemIndexPath) computing its correct frame and play with the z-index.



But you could also simply try to invalidate all the layout like so:



func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
layout = CollectionViewLayout()
layout.delegate = self
collectionView.setCollectionViewLayout(layout, animated: true)



and override:



override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint 
return collectionView?.contentOffset ?? .zero



to avoid a wrong target content offset computation when the layout is invalidated.



fix






share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40711925%2fuicollectionview-animating-cell-beyond-bounds%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5







    +500








    You should add some code or at least a gif of your UI problem.



    I tried to replicate your problem using a basic UICollectionViewLayout subclass :



    protocol CollectionViewLayoutDelegate: AnyObject 
    func heightForItem(at indexPath: IndexPath) -> CGFloat


    class CollectionViewLayout: UICollectionViewLayout
    weak var delegate: CollectionViewLayoutDelegate?

    private var itemAttributes: [UICollectionViewLayoutAttributes] = []

    override func prepare()
    super.prepare()
    itemAttributes = generateItemAttributes()


    override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint
    return collectionView?.contentOffset ?? .zero
    return super.targetContentOffset(forProposedContentOffset: proposedContentOffset)


    override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?
    return itemAttributes.first $0.indexPath == indexPath


    override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?
    return itemAttributes.filter $0.frame.intersects(rect)


    private func generateItemAttributes() -> [UICollectionViewLayoutAttributes]
    var offset: CGFloat = 0
    return (0..<numberOfItems()).map index in
    let indexPath = IndexPath(item: index, section: 0)
    let frame = CGRect(
    x: 0,
    y: offset,
    width: collectionView?.bounds.width ?? 0,
    height: delegate?.heightForItem(at: indexPath) ?? 0
    )
    offset = frame.maxY
    let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
    attributes.frame = frame
    return attributes





    In a simple UIViewController, I reloaded the first cell each time a cell is selected:



    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
    updatedIndexPath = IndexPath(item: 0, section: 0)
    collectionView.reloadItems(at: [updatedIndexPath])



    In that case, I faced an animation like this:



    bug



    How to fix it ?



    I think you could try to tweak the attributes returned by super.finalLayoutAttributesForDisappearingItem(at: itemIndexPath) computing its correct frame and play with the z-index.



    But you could also simply try to invalidate all the layout like so:



    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
    layout = CollectionViewLayout()
    layout.delegate = self
    collectionView.setCollectionViewLayout(layout, animated: true)



    and override:



    override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint 
    return collectionView?.contentOffset ?? .zero



    to avoid a wrong target content offset computation when the layout is invalidated.



    fix






    share|improve this answer































      5







      +500








      You should add some code or at least a gif of your UI problem.



      I tried to replicate your problem using a basic UICollectionViewLayout subclass :



      protocol CollectionViewLayoutDelegate: AnyObject 
      func heightForItem(at indexPath: IndexPath) -> CGFloat


      class CollectionViewLayout: UICollectionViewLayout
      weak var delegate: CollectionViewLayoutDelegate?

      private var itemAttributes: [UICollectionViewLayoutAttributes] = []

      override func prepare()
      super.prepare()
      itemAttributes = generateItemAttributes()


      override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint
      return collectionView?.contentOffset ?? .zero
      return super.targetContentOffset(forProposedContentOffset: proposedContentOffset)


      override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?
      return itemAttributes.first $0.indexPath == indexPath


      override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?
      return itemAttributes.filter $0.frame.intersects(rect)


      private func generateItemAttributes() -> [UICollectionViewLayoutAttributes]
      var offset: CGFloat = 0
      return (0..<numberOfItems()).map index in
      let indexPath = IndexPath(item: index, section: 0)
      let frame = CGRect(
      x: 0,
      y: offset,
      width: collectionView?.bounds.width ?? 0,
      height: delegate?.heightForItem(at: indexPath) ?? 0
      )
      offset = frame.maxY
      let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
      attributes.frame = frame
      return attributes





      In a simple UIViewController, I reloaded the first cell each time a cell is selected:



      func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
      updatedIndexPath = IndexPath(item: 0, section: 0)
      collectionView.reloadItems(at: [updatedIndexPath])



      In that case, I faced an animation like this:



      bug



      How to fix it ?



      I think you could try to tweak the attributes returned by super.finalLayoutAttributesForDisappearingItem(at: itemIndexPath) computing its correct frame and play with the z-index.



      But you could also simply try to invalidate all the layout like so:



      func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
      layout = CollectionViewLayout()
      layout.delegate = self
      collectionView.setCollectionViewLayout(layout, animated: true)



      and override:



      override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint 
      return collectionView?.contentOffset ?? .zero



      to avoid a wrong target content offset computation when the layout is invalidated.



      fix






      share|improve this answer





























        5







        +500







        5







        +500



        5






        +500





        You should add some code or at least a gif of your UI problem.



        I tried to replicate your problem using a basic UICollectionViewLayout subclass :



        protocol CollectionViewLayoutDelegate: AnyObject 
        func heightForItem(at indexPath: IndexPath) -> CGFloat


        class CollectionViewLayout: UICollectionViewLayout
        weak var delegate: CollectionViewLayoutDelegate?

        private var itemAttributes: [UICollectionViewLayoutAttributes] = []

        override func prepare()
        super.prepare()
        itemAttributes = generateItemAttributes()


        override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint
        return collectionView?.contentOffset ?? .zero
        return super.targetContentOffset(forProposedContentOffset: proposedContentOffset)


        override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?
        return itemAttributes.first $0.indexPath == indexPath


        override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?
        return itemAttributes.filter $0.frame.intersects(rect)


        private func generateItemAttributes() -> [UICollectionViewLayoutAttributes]
        var offset: CGFloat = 0
        return (0..<numberOfItems()).map index in
        let indexPath = IndexPath(item: index, section: 0)
        let frame = CGRect(
        x: 0,
        y: offset,
        width: collectionView?.bounds.width ?? 0,
        height: delegate?.heightForItem(at: indexPath) ?? 0
        )
        offset = frame.maxY
        let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
        attributes.frame = frame
        return attributes





        In a simple UIViewController, I reloaded the first cell each time a cell is selected:



        func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
        updatedIndexPath = IndexPath(item: 0, section: 0)
        collectionView.reloadItems(at: [updatedIndexPath])



        In that case, I faced an animation like this:



        bug



        How to fix it ?



        I think you could try to tweak the attributes returned by super.finalLayoutAttributesForDisappearingItem(at: itemIndexPath) computing its correct frame and play with the z-index.



        But you could also simply try to invalidate all the layout like so:



        func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
        layout = CollectionViewLayout()
        layout.delegate = self
        collectionView.setCollectionViewLayout(layout, animated: true)



        and override:



        override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint 
        return collectionView?.contentOffset ?? .zero



        to avoid a wrong target content offset computation when the layout is invalidated.



        fix






        share|improve this answer















        You should add some code or at least a gif of your UI problem.



        I tried to replicate your problem using a basic UICollectionViewLayout subclass :



        protocol CollectionViewLayoutDelegate: AnyObject 
        func heightForItem(at indexPath: IndexPath) -> CGFloat


        class CollectionViewLayout: UICollectionViewLayout
        weak var delegate: CollectionViewLayoutDelegate?

        private var itemAttributes: [UICollectionViewLayoutAttributes] = []

        override func prepare()
        super.prepare()
        itemAttributes = generateItemAttributes()


        override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint
        return collectionView?.contentOffset ?? .zero
        return super.targetContentOffset(forProposedContentOffset: proposedContentOffset)


        override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?
        return itemAttributes.first $0.indexPath == indexPath


        override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?
        return itemAttributes.filter $0.frame.intersects(rect)


        private func generateItemAttributes() -> [UICollectionViewLayoutAttributes]
        var offset: CGFloat = 0
        return (0..<numberOfItems()).map index in
        let indexPath = IndexPath(item: index, section: 0)
        let frame = CGRect(
        x: 0,
        y: offset,
        width: collectionView?.bounds.width ?? 0,
        height: delegate?.heightForItem(at: indexPath) ?? 0
        )
        offset = frame.maxY
        let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
        attributes.frame = frame
        return attributes





        In a simple UIViewController, I reloaded the first cell each time a cell is selected:



        func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
        updatedIndexPath = IndexPath(item: 0, section: 0)
        collectionView.reloadItems(at: [updatedIndexPath])



        In that case, I faced an animation like this:



        bug



        How to fix it ?



        I think you could try to tweak the attributes returned by super.finalLayoutAttributesForDisappearingItem(at: itemIndexPath) computing its correct frame and play with the z-index.



        But you could also simply try to invalidate all the layout like so:



        func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) 
        layout = CollectionViewLayout()
        layout.delegate = self
        collectionView.setCollectionViewLayout(layout, animated: true)



        and override:



        override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint 
        return collectionView?.contentOffset ?? .zero



        to avoid a wrong target content offset computation when the layout is invalidated.



        fix







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 28 at 9:03

























        answered Mar 27 at 17:29









        GaétanZGaétanZ

        3,1621 gold badge14 silver badges28 bronze badges




        3,1621 gold badge14 silver badges28 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40711925%2fuicollectionview-animating-cell-beyond-bounds%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현