swift - uitableview展开缩放动画
效果
源码:https://github.com/youxianming/swift-animations
// // headerviewtapanimationcontroller.swift // swift-animations // // created by youxianming on 16/8/9. // 凯发网娱乐官网下载 copyright © 2016年 youxianming. all rights reserved. // import uikit class headerviewtapanimationcontroller: normaltitleviewcontroller, uitableviewdelegate, uitableviewdatasource { private var classes : [classmodel]! private var tableview : uitableview! private var sectionfirstload : bool! private weak var tmpheadview : classheaderview! override func setup() { super.setup() sectionfirstload = false // tableview. tableview = uitableview(frame: (contentview?.bounds)!) tableview.datasource = self tableview.delegate = self tableview.rowheight = 60 tableview.sectionheaderheight = 30 tableview.separatorstyle = .none contentview?.addsubview(tableview!) // register. classheaderview.registertotableview(tableview) studentinfocell.registertotableview(tableview) // data source. let aitna = classmodel(classname: "aitna") aitna.expend = false aitna.students?.append(studentmodel(name: "y.x.m.", age: 27)) aitna.students?.append(studentmodel(name: "leif", age: 12)) aitna.students?.append(studentmodel(name: "lennon", age: 23)) aitna.students?.append(studentmodel(name: "jerome", age: 19)) aitna.students?.append(studentmodel(name: "isidore", age: 15)) let melete = classmodel(classname: "melete") melete.expend = false melete.students?.append(studentmodel(name: "merle", age: 17)) melete.students?.append(studentmodel(name: "paddy", age: 31)) melete.students?.append(studentmodel(name: "perry", age: 59)) melete.students?.append(studentmodel(name: "philip", age: 23)) let aoede = classmodel(classname: "aoede") aoede.expend = false aoede.students?.append(studentmodel(name: "verne", age: 12)) aoede.students?.append(studentmodel(name: "vincent", age: 89)) aoede.students?.append(studentmodel(name: "walter", age: 43)) aoede.students?.append(studentmodel(name: "zachary", age: 21)) let dione = classmodel(classname: "dione") dione.expend = false dione.students?.append(studentmodel(name: "timothy", age: 72)) dione.students?.append(studentmodel(name: "roderick", age: 34)) dione.students?.append(studentmodel(name: "quentin", age: 12)) dione.students?.append(studentmodel(name: "paddy", age: 75)) let adanos = classmodel(classname: "adanos") adanos.expend = false adanos.students?.append(studentmodel(name: "mortimer", age: 43)) adanos.students?.append(studentmodel(name: "michael", age: 64)) adanos.students?.append(studentmodel(name: "kevin", age: 23)) adanos.students?.append(studentmodel(name: "jeremy", age: 21)) classes = [classmodel]() classes.append(aitna) classes.append(melete) classes.append(aoede) classes.append(dione) classes.append(adanos) // expend animations. gcdqueue.executeinmainqueue({ self.sectionfirstload = true self.tableview.insertsections(nsindexset(indexesinrange: nsmakerange(0, self.classes.count)), withrowanimation: .fade) gcdqueue.executeinmainqueue({ self.tmpheadview.buttonevent() }, afterdelayseconds: 0.4) }, afterdelayseconds: 0.3) } // mark: uitableview's delegate & datasource. func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { let classmodel = classes[section] if classmodel.expend == true { return (classmodel.students?.count)! } else { return 0 } } func numberofsectionsintableview(tableview: uitableview) -> int { if sectionfirstload == false { return 0 } else { return classes.count } } func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let classmodel = classes[indexpath.section] let customcell = tableview.dequeuereusablecellwithidentifier("studentinfocell") as! customcell customcell.data = classmodel.students![indexpath.row] customcell.indexpath = indexpath customcell.loadcontent() return customcell } func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { tableview.selectedeventwithindexpath(indexpath) } func tableview(tableview: uitableview, viewforheaderinsection section: int) -> uiview? { let headerview = tableview.dequeuereusableheaderfooterviewwithidentifier("classheaderview") as! classheaderview headerview.section = section headerview.data = classes[section] headerview.tableview = tableview headerview.loadcontent() if tmpheadview == nil && section == 0 { tmpheadview = headerview } return headerview } }
以上就是本文的全部内容,希望对大家的学习有所帮助,