分組表視圖中的中間動畫看起來很糟糕 (Middle animation in grouped table view looks horrible)


問題描述

分組表視圖中的中間動畫看起來很糟糕 (Middle animation in grouped table view looks horrible)

I've found similar question, but there is no answer (sorry, answer just doesn't work).

So I have grouped table and I want to animate content update instead of doing [tableView reloadData]. I do that by using this piece of code:

// Data source already updated here, but reloadData wasn't called
[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationMiddle];
[self.tableView endUpdates];

I uploaded 2 examples of the animation:

  • Plain: http://cl.ly/3u1M3l1w3V3J (slow motion)
  • Grouped: http://cl.ly/1O3Z2M280n0z (slow motion)

As you can see difference is huge. I don't change my code at all, just change tableView style in the storyboard.

Does it men that there is no other way then subclassing UITableView and UITableViewCell and implement my very own animation using CoreAnimation?


參考解法

方法 1:

Implementing your own animation with CoreAnimation shouldn't be necessary when it comes to animating the rows of the table. 

UITableView supports much more advanced animations than simply reloading a section and I suggest that you take a look at them. 

Since you are shuffling the rows in your videos you should take a look at moveRowAtIndexPath:toIndexPath: (on UITableView). You put the calls to it within beginUpdates and endUpdates.

By knowing the order before and after the re-shuffle you can move all the rows into their new places and have them slide into their correct place.

It will take some thinking to figure out where each row should go but it will be much easier than rolling your completely custom solution.

(by OgreSwampDavid Rönnqvist)

參考文件

  1. Middle animation in grouped table view looks horrible (CC BY-SA 3.0/4.0)

#cocoa-touch #core-animation #iOS #uitableview






相關問題

防止 UITableView 在自定義子視圖處理觸摸時滾動 (Prevent UITableView from scrolling when custom subview is handling touches)

NSMutableArray removeObjectAtIndex 在第二次執行時崩潰 (NSMutableArray removeObjectAtIndex crashes on second execution)

Apakah NSURLConnections termasuk dalam model atau pengontrol saya? (Do NSURLConnections belong in my model or controller?)

Lợi ích của việc sử dụng NSString tĩnh cho CellIdentifier là gì? (Whats the advantage of using a static NSString for CellIdentifier?)

CGContextRef 中的坐標係是什麼樣的? (How does the coordinate system in an CGContextRef look like?)

無法在不崩潰的情況下設置 ABPeoplePickerNavigationController 的 addressBook 屬性 (Can't set the addressBook property of ABPeoplePickerNavigationController without crashing)

tableViewHeader 拒絕多個子視圖 (tableViewHeader rejecting multiple sub-views)

界面生成器添加了一個標籤欄按鈕,但未顯示 (Interface builder added one tab bar button, but not showing up)

iVar getter / 方法同名? (iVar getter / method with same name?)

如何更改主視圖是基於導航的應用程序! (how to change main view is navigation based app!)

捕捉返回按鈕導航事件 (Catching back button navigation event)

如何將對象轉發到單獨的子視圖? (How can i forward objects to separate subviews?)







留言討論