使用大单元格插入表格单元格动画

时间:2017-10-11 15:57:26

标签: ios swift uitableview ios-animations

有人可以帮我搞动画吗?我最后的目标是显示一个细胞的细节,我试过:固定高度,用另一个细胞替换细胞,在接触细胞下面插入新细胞。所有解决方案都与动画有类似的问题。细节单元格比其他单元格大,当动画开始时,可​​以在其他单元格下面看到新单元格。

示例项目中的问题仅发生在最后两个单元格中。最后一个中的结果动画有点不同,但即使使用自动,结果也是一样。

func loadData(){

   let userID = Auth.auth().currentUser!.uid
    Database.database().reference().child("notification").child(userID).observe(.childAdded, with: { (snapshot) in
        guard let dictionary = snapshot.value as? [String: Any] else { return }
        let uid = dictionary["uid"] as? String
        let postId = dictionary["postID"] as? String

        Database.fetchUserWithUID(uid: uid!, completion: { (snapshot) in
            Database.fetchPostWithUID(uid: userID, postId: postId!, completion: { (postShot) in
                Database.fetchVideoPostWithUID(uid: userID, postId: postId!, completion: { (videoShot) in

                    let comment = notification(user: snapshot, post: postShot, videoPost: videoShot, dictionary: dictionary)
                    self.notifications.append(comment)
                    self.notificationTableView?.reloadData()
                })
            })
        })
    })
}

extension Database {

    static func fetchUserWithUID(uid: String, completion: @escaping (userAccount) -> ()) {
        Database.database().reference().child("user").child(uid).observeSingleEvent(of: .value, with: { (snapshot) in

        let user = userAccount(snapshot:snapshot)
         completion(user)
            })
    }

    static func fetchPostWithUID(uid: String, postId: String,  completion: @escaping (Post) -> ()) {
        Database.database().reference().child("post").child(uid).child(postId).observeSingleEvent(of: .value, with: { (snapshot) in

            if snapshot.exists() {
                let post = Post(snapshot:snapshot)
                completion(post)
            }else{
        // Not sure what to write here when snapshot is equal to nil

        })
}

  static func fetchVideoPostWithUID(uid: String, postId: String,  completion: @escaping (videoPost) -> ()) {
        Database.database().reference().child("videoPost").child(uid).child(postId).observeSingleEvent(of: .value, with: { (snapshot) in

            if snapshot.exists(){          
            let post = videoPost(snapshot:snapshot)
            completion(post)
            }else{
        // Again not sure what to write here when snapshot is equal to nil

            }            
        })
}

开始动画:https://i.stack.imgur.com/PcQty.png

最终结果:https://i.stack.imgur.com/uSljt.png

我创建了一个示例项目(插入新单元格):https://github.com/elanovasconcelos/TestTableAnimation

1 个答案:

答案 0 :(得分:0)

我的主要问题是桌子需要一个页脚才能使动画看起来正确。我添加了一个比大单元格更大的单元,之后动画就可以了。