| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

Swift 清新的单元格折叠动画类及演示 - FoldingCell

FoldingCell

CocoaPods CocoaPods 推ter Travis

shot on dribbbleAnimation

Requirements

  • iOS 8.0+
  • Xcode 7.2

Installation

Just add the FoldingCell.swift file to your project.

or use CocoaPods with Podfile:

pod 'FoldingCell', '~> 0.3'

Solution

Solution

Usage

1) Create a new cell inheriting from FoldingCell

2) Add a UIView to your cell in your storyboard or nib file, inheriting from RotatedView. Connect the outlet from this view to the cell property foregroundView. Add constraints from this view to the superview, as in this picture: 1.1

(constants of constraints may be different). Add the identifier ForegroundViewTop for the top constraint. (This view will be shown when the cell is in its normal state).

3) Add other UIViews to your cell, connect the outlet from this view to the cell property containerView. Add constraints from this view to the superview like in the picture:

1.2

(constants of constraints may be different). Add the identifier "ContainerViewTop" for the top constraint. (This view will be shown when the cell is opened)

Your result should be something like this picture: 1.3

4) Set @IBInspectable var itemCount: NSInteger property is a count of folding (it IBInspectable you can set in storyborad). range 2 or greater. Default value is 2

Ok, we've finished configuring the cell.

5) Adding code to your UITableViewController

5.1) Add constants:

let kCloseCellHeight: CGFloat = *** // equal or greater foregroundView height       let kOpenCellHeight: CGFloat = *** // equal or greater containerView height

5.2) Add property

var cellHeights = [CGFloat]()
 create in viewDidLoad:
override func viewDidLoad() {          super.viewDidLoad()            for _ in 0...kRowsCount {              cellHeights.append(kCloseCellHeight)          }      }

5.3) Override method:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {          return cellHeights[indexPath.row]      }

5.4) Added code to method:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {          let cell = tableView.cellForRowAtIndexPath(indexPath) as! FoldingCell            var duration = 0.0          if cellHeights[indexPath.row] == kCloseCellHeight { // open cell              cellHeights[indexPath.row] = kOpenCellHeight              cell.selectedAnimation(true, animated: true, completion: nil)              duration = 0.5          } else {// close cell              cellHeights[indexPath.row] = kCloseCellHeight              cell.selectedAnimation(false, animated: true, completion: nil)              duration = 1.1          }            UIView.animateWithDuration(duration, delay: 0, options: .CurveEaseOut, animations: { () -> Void in              tableView.beginUpdates()              tableView.endUpdates()          }, completion: nil)      }

5.5) Control if the cell is open or closed

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {            if cell is FoldingCell {              let foldingCell = cell as! FoldingCell                if cellHeights![indexPath.row] == kCloseCellHeight {                  foldingCell.selectedAnimation(false, animated: false, completion:nil)              } else {                  foldingCell.selectedAnimation(true, animated: false, completion: nil)              }          }      }

6) Add this code to your new cell class

override func animationDuration(itemIndex:NSInteger, type:AnimationType)-> NSTimeInterval {            // durations count equal it itemCount          let durations = [0.33, 0.26, 0.26] // timing animation for each view          return durations[itemIndex]      }

Licence

Adaptive tab bar is released under the MIT license. See LICENSE for details.

About

The project maintained by app development agency Ramotion Inc. See our other open-source projects or hire us to design, develop, and grow your product.

推ter URL 推ter Follow

项目地址: https://github.com/Ramotion/folding-cell

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1454490795901.html
Apple Swift开发 folding-cell - Swift - GitHub