Resize scroll animation

I am trying to create a size switching animation for this simple custom TUIScrollView class (from an open source TwUI project and very similar to the UIScrollView) that I created. It's called TUILayout and supports horizontal layout, as well as vertical, animated inserts and deletes, and has a more declarative way of providing data for cells, which I prefer for delegation. It recycles views similar to TUITableView or UITableView. In any case, if you want to follow, this is just one class and is located here.

https://github.com/mrjjwright/TUILayout .

In the code example, the user clicks the blue button in the lower left corner and all the lines are smoothly compressed to a size where the user can reorder and delete several lines (right-click on the line in the example to see this in action), etc. and then the user switches the lines back to their original size by pressing the blue button again.

By doing this resizing in setObjectHeight:animated , I first resize the model objects that represent the strings, recalculate and set the contentSize in TUIScrollView, cyclically in all new views (say 10 views will correspond to a reduced view, so dequeueReusableView and addSubview are called 10 times) And finally, I am animating the frames of all the views, their size and location in layoutSubviews.

The result is that scrollview is correctly compressed to a size in which the scroll bar is no longer displayed, images that are smoothly updated on the screen, to their reduced size, but recently added objects that can now fit into the visibleRect animation later as one block of subtitles .

Thus, all the recently added subviews lag behind the views that were on the screen, and I cannot understand why the animation doesn’t all happen together. I have tried many different combinations of things with no luck, including CATransactions. I am wondering if this works with CAScrollLayer or if someone can help me think this through.

A more general problem is how to smoothly handle resizing animations on scrollviews that recycle their views, and I looked at several other grids in the iOS world and got some inspiration, but I'm looking more.

Thank!

0
cocoa core-animation
Dec 04 2018-11-11T00:
source share
1 answer

I think I could solve my own problem here (as I was making my bed this morning, it hit me). I made the current runloop work after looping in all the necessary subqueries, and it’s very important not to set the contentSize scroll until the loop cycle completes and adds the necessary subviews for the animation. To start the startup loop, I used the trick from this SO question :

  skipLayout = YES; [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate: [NSDate date]]; skipLayout = NO; 

If skipLayout set to TUILayout , it simply returns from layoutSubviews, so the views you just added are not immediately deleted using the layout code. Forcing the execution cycle to run ensures that all sub-items are on screen for animation. After that, I executed an animated size layout. I updated the code on github if anyone is interested. I will leave this question open for a while to get more information.

+1
Dec 04 '11 at 17:40
source share



All Articles