iOS UITableView展開(kāi)縮放動(dòng)畫(huà)實(shí)例代碼
Swift - UITableView展開(kāi)縮放動(dòng)畫(huà)
效果
源碼: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 } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- iOS應(yīng)用開(kāi)發(fā)中對(duì)UIImage進(jìn)行截取和縮放的方法詳解
- iOS應(yīng)用開(kāi)發(fā)中使用UIScrollView控件來(lái)實(shí)現(xiàn)圖片縮放
- iOS開(kāi)發(fā)中Quartz2D控制圓形縮放和實(shí)現(xiàn)刷幀效果
- iOS實(shí)現(xiàn)點(diǎn)擊微信頭像(放大、縮放、保存)效果
- iOS tableView實(shí)現(xiàn)頭部拉伸并改變導(dǎo)航條漸變色
- iOS開(kāi)發(fā)之tableView實(shí)現(xiàn)左滑刪除功能
- iOS App中UITableView左滑出現(xiàn)刪除按鈕及其cell的重用
- 解決iOS11刷新tableview會(huì)出現(xiàn)漂移的現(xiàn)象
- IOS實(shí)現(xiàn)左右兩個(gè)TableView聯(lián)動(dòng)效果
- iOS TableView頭視圖根據(jù)偏移量下拉縮放效果
相關(guān)文章
Swift實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了Swift實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01swift如何利用系統(tǒng)庫(kù)將漢字轉(zhuǎn)換為拼音詳解
將漢字轉(zhuǎn)換為拼音更利于我們大家開(kāi)發(fā)搜索功能,所以這篇文章主要給大家介紹了關(guān)于swift如何利用系統(tǒng)庫(kù)將漢字轉(zhuǎn)換為拼音的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-10-10Swift中的條件切換語(yǔ)句switch...case學(xué)習(xí)教程
這篇文章主要介紹了Swift中的條件切換語(yǔ)句switch...case學(xué)習(xí)教程,Swift中的switch...case支持的數(shù)據(jù)類(lèi)型很多,非常之強(qiáng)大,需要的朋友可以參考下2016-04-04Swift?并發(fā)修改Sendable?閉包實(shí)例詳解
這篇文章主要為大家介紹了Swift?并發(fā)修改Sendable?閉包實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10