登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

可折叠视图

[复制链接]
来自: qingge545 分类: iOS精品源码 上传时间: 2017-4-25 16:14:13

项目介绍:

header

FoldingCell

CocoaPods
CocoaPods
CocoaPods
Carthage compatible
Twitter
Travis
codebeat badge
Carthage compatible
Analytics

About

This project is maintained by Ramotion, Inc.

We specialize in the designing and coding of custom UI for Mobile Apps and Websites.

Looking for developers for your project?

Animation

Requirements

  • iOS 8.0+

  • Xcode 7.3

Installation

Just add the FoldingCell.swift file to your project.

or use CocoaPods with Podfile:

pod 'FoldingCell', '~> 2.0.3' 

or Carthage users can simply add Mantle to their Cartfile:

github "Ramotion/folding-cell"

or just drag and drop FoldingCell.swift file to your project

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). Connect the outlet from this top constraint to the cell property foregroundViewTop
. (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). Connect the outlet from this top constraint to the cell property containerViewTop.
(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 storyboard). 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:

fileprivate struct C {
  struct CellHeight {
    static let close: CGFloat = *** // equal or greater foregroundView height
    static let open: CGFloat = *** // equal or greater containerView height
  }
}

5.2) Add property for calculate cells height

     var cellHeights = (0..<CELLCOUNT).map { _ in C.CellHeight.close }

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) {
        guard case let cell as FoldingCell = tableView.cellForRowAtIndexPath(indexPath) else {
          return
        }

        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: { _ 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 case let cell as FoldingCell = cell {
            if cellHeights![indexPath.row] == C.cellHeights.close {
                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]
    }

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

相关源码推荐:

    我来说两句
    *滑动验证:
    所有评论(261)
    qingge545 2017-4-26 08:48:15
    https://pan.baidu.com/s/1geK3czD  贴一下仿写代码链接,发帖的时候,网速不好 没传上去
    回复
    littleRed 2017-4-26 17:08:25
    好好 学习了 确实不错
    回复
    AlonMessi 2017-4-26 17:08:28
    感谢分享,code4app有你更精彩
    回复
    hellokenken 2017-4-26 17:08:37
    不错不错,楼主辛苦了。。。
    回复
    kengsir 2017-4-26 17:09:54
    感谢大神分享,必须顶!
    回复
    phoiu 2017-4-26 17:10:18
    code4app好的内容真的很多~赞
    回复
    亚洲龙哥 2017-4-27 09:40:59
    学习学习!
    回复
    code4app热心网友 2017-4-27 10:47:47
    我只是路过打酱油的。
    回复
    code4app热心网友 2017-4-27 11:22:56
    很给力,Code4App有你更精彩!
    回复
    提取码:  下载次数:270 状态:已购或VIP 售价:0(原价:10)金钱 下载权限:初级码农 
    3722 5 270
    相关代码
      联系我们
      首页/微信公众账号投稿

      帖子代码编辑/版权问题

      QQ:435399051,742864542

      如何获得代码达人称号?

      代码贡献英雄榜
      用户名 下载数
      代码分类
      通过邮件订阅最新 Code4App 信息
      上一条 /4 下一条
      联系我们
      关闭
      合作电话:
      13802416937
      Email:
      435399051@qq.com
      商务市场合作/投稿
      问题反馈及帮助
      联系我们

      广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

      快速回复 返回顶部 返回列表