iOS UITableView展開縮放動(dòng)畫實(shí)例代碼
Swift - UITableView展開縮放動(dòng)畫

效果

源碼: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)用開發(fā)中對(duì)UIImage進(jìn)行截取和縮放的方法詳解
- iOS應(yīng)用開發(fā)中使用UIScrollView控件來(lái)實(shí)現(xiàn)圖片縮放
- iOS開發(fā)中Quartz2D控制圓形縮放和實(shí)現(xiàn)刷幀效果
- iOS實(shí)現(xiàn)點(diǎn)擊微信頭像(放大、縮放、保存)效果
- iOS tableView實(shí)現(xiàn)頭部拉伸并改變導(dǎo)航條漸變色
- iOS開發(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中switch語(yǔ)句對(duì)case的數(shù)據(jù)類型匹配的支持
這篇文章主要介紹了Swift中switch語(yǔ)句對(duì)case的數(shù)據(jù)類型匹配的支持,Swift中switch...case語(yǔ)句支持多種數(shù)據(jù)類型的匹配判斷,十分強(qiáng)大,需要的朋友可以參考下2016-04-04
SwiftUI使用Paths和AnimatableData實(shí)現(xiàn)酷炫的顏色切換動(dòng)畫
這篇文章主要介紹了SwiftUI使用Paths和AnimatableData實(shí)現(xiàn)酷炫的顏色切換動(dòng)畫,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2020-05-05
SwiftUI?List在MacOS中的性能優(yōu)化示例
這篇文章主要為大家介紹了SwiftUI?List在MacOS中的性能優(yōu)化示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
Swift UILable 設(shè)置內(nèi)邊距實(shí)例代碼
本文主要介紹Swift UILable 設(shè)置內(nèi)邊距,這里提供示例代碼供大家參考,有需要的小伙伴可以看下2016-07-07
openstack重啟swift服務(wù)后報(bào)錯(cuò)問(wèn)題解決方案
這篇文章主要介紹了解決openstack重啟swift服務(wù)后報(bào)錯(cuò),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-08-08
Swift網(wǎng)絡(luò)請(qǐng)求庫(kù)Alamofire使用詳解
這篇文章主要為大家詳細(xì)介紹了Swift網(wǎng)絡(luò)請(qǐng)求庫(kù)Alamofire的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
Swift 3.0基礎(chǔ)學(xué)習(xí)之類與結(jié)構(gòu)體
最近在學(xué)swift 3.0,主要看的是蘋果的官方文檔,這里只是根據(jù)自己看官方文檔的理解所做的一些記錄,不是完整的翻譯,希望也對(duì)你有所幫助。下面這篇文章主要介紹了Swift 3.0基礎(chǔ)學(xué)習(xí)之類與結(jié)構(gòu)體的相關(guān)資料,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-03-03

