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

