Swift and swiftcode

Source: Internet
Author: User

Swift and swiftcode

Swift-UITableView scaling Animation

 

Effect

 

Source code

Https://github.com/YouXianMing/Swift-Animations

/// HeaderViewTapAnimationController. swift // Swift-Animations /// Created by YouXianMing on 16/8/9. // Copyright©2016 YouXianMing. All rights reserved. // import UIKitclass 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.exe cuteInMainQueue ({self. sectionFirstLoad = true self. tableView. insertSections (NSIndexSet (indexesInRange: NSMakeRange (0, self. classes. count), withRowAnimation :. fade) GCDQueue.exe cuteIn MainQueue ({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")! 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")! ClassHeaderView headerView. section = section headerView. data = classes [section] headerView. tableView = tableView headerView. loadContent () if tmpHeadView = nil & section = 0 {tmpHeadView = headerView} return headerView }}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.