Swift - 實現點擊cell動態修改高度

来源:http://www.cnblogs.com/YouXianMing/archive/2016/09/01/5830862.html
-Advertisement-
Play Games

Swift - 實現點擊cell動態修改高度 效果 源碼 https://github.com/YouXianMing/Swift-Animations ...


Swift - 實現點擊cell動態修改高度

 

效果

 

源碼

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

//
//  TapCellAnimationController.swift
//  Swift-Animations
//
//  Created by YouXianMing on 16/8/30.
//  Copyright © 2016年 YouXianMing. All rights reserved.
//

import UIKit

class TapCellAnimationController: NormalTitleViewController, UITableViewDelegate, UITableViewDataSource {
    
    private var tableView : UITableView!
    private var datas     : [CellDataAdapter]!
    
    override func setup() {
        
        super.setup()
        
        datas = [CellDataAdapter]()
        
        tableView                = UITableView(frame: (contentView?.bounds)!)
        tableView.delegate       = self
        tableView.dataSource     = self
        tableView.separatorStyle = .None
        ShowTextCell.RegisterTo(tableView)
        contentView?.addSubview(tableView)
        
        func addText(string : String) {
            
            let model = ShowTextModel(string)
            
            datas.append(ShowTextCell.Adapter(
                data       : model,
                cellHeight : ShowTextCell.HeightWithData(model),
                type       : EShowTextCellType.NormalType.rawValue))
        }
        
        GCDQueue.executeInMainQueue({
            
            addText("AFNetworking is a delightful networking library for iOS and Mac OS X. It's built on top of the Foundation URL Loading System, extending the powerful high-level networking abstractions built into Cocoa. It has a modular architecture with well-designed, feature-rich APIs that are a joy to use. Perhaps the most important feature of all, however, is the amazing community of developers who use and contribute to AFNetworking every day. AFNetworking powers some of the most popular and critically-acclaimed apps on the iPhone, iPad, and Mac. Choose AFNetworking for your next project, or migrate over your existing projects—you'll be happy you did!")
            
            addText("黃色的樹林里分出兩條路,可惜我不能同時去涉足,我在那路口久久佇立,我向著一條路極目望去,直到它消失在叢林深處。但我卻選了另外一條路,它荒草萋萋,十分幽寂,顯得更誘人、更美麗,雖然在這兩條小路上,都很少留下旅人的足跡,雖然那天清晨落葉滿地,兩條路都未經腳印污染。呵,留下一條路等改日再見!但我知道路徑延綿無盡頭,恐怕我難以再回返。也許多少年後在某個地方,我將輕聲嘆息把往事回顧,一片樹林里分出兩條路,而我選了人跡更少的一條,從此決定了我一生的道路。")
            
            addText("★タクシー代がなかったので、家まで歩いて帰った。★もし事故が発生した場所、このレバーを引いて列車を止めてください。(丁)為了清楚地表示出一個短語或句節,其後須標逗號。如:★この薬を、夜寢る前に一度、朝起きてからもう一度、飲んでください。★私は、空を飛ぶ鳥のように、自由に生きて行きたいと思った。*****為了清楚地表示詞語與詞語間的關係,須標逗號。標註位置不同,有時會使句子的意思發生變化。如:★その人は大きな音にびっくりして、橫から飛び出した子供にぶつかった。★その人は、大きな音にびっくりして橫から飛び出した子供に、ぶつかった。")
            
            addText("Two roads diverged in a yellow wood, And sorry I could not travel both And be one traveler, long I stood And looked down one as far as I could To where it bent in the undergrowth; Then took the other, as just as fair, And having perhaps the better claim, Because it was grassy and wanted wear; Though as for that the passing there Had worn them really about the same, And both that morning equally lay In leaves no step had trodden black. Oh, I kept the first for another day! Yet knowing how way leads on to way, I doubted if I should ever come back. I shall be telling this with a sigh Somewhere ages and ages hence: Two roads diverged in a wood, and I- I took the one less traveled by, And that has made all the difference.")
            
            var indexPaths = [NSIndexPath]()
            for i in 0 ..< self.datas.count {
                
                indexPaths.append(NSIndexPath(forItem: i, inSection: 0))
            }
            self.tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: .Fade)
            
            GCDQueue.executeInMainQueue({
                
                let cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forItem: 0, inSection: 0)) as! CustomCell
                cell.selectedEvent()
                
                }, afterDelaySeconds: 0.5)
            
            }, afterDelaySeconds: 0.5)
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        return tableView.dequeueAndLoadContentReusableCellFromAdapter(datas[indexPath.row], indexPath: indexPath, tableView: tableView)
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return datas.count
    }
    
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        
        return datas[indexPath.row].cellHeight!
    }
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        tableView.selectedEventWithIndexPath(indexPath)
    }
}

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • getFragmentManager()和getSupportFragmentManager() ...
  • android Button的enabled和clickabled的區別 ...
  • 上篇博客《iOS逆向工程之KeyChain與Snoop-it》中已經提到了,App間的數據共用可以使用KeyChian來實現。本篇博客就實戰一下呢。開門見山,本篇博客會封裝一個登錄用的SDK, 該登錄SDK中包括登錄、註冊、忘記密碼等功能,當然該SDK中包括這些功能的UI、數據驗證等業務邏輯、網路請 ...
  • 這裡利用 ProgressBar 即時顯示下載進度。 途中碰到的問題: 1、主線程中不能打開 URL,和只能在主線程中使用 Toast 等 2、子線程不能修改 UI 3、允許網路協議 4、暫停下載和繼續下載 ........ fragment_main 佈局文件 1 <RelativeLayout ...
  • Drawable animation可以載入Drawable資源實現幀動畫。AnimationDrawable是實現Drawable animations的基本類。 這裡用AnimationDrawable 簡單模擬動態圖的實現。 fragment_main 佈局文件 只需要放一個 ImageVie ...
  • 草原上的兩匹馬! 打從當年微信開始佈局公眾號之初時,估計就已經想到了與支付寶正面衝突的場面,所以微信先來個瞞天過海,在春晚搞了個微信紅包,那叫一個火呀,此時的云云隱隱感覺到些許不安。 早期的微信開發者可能都知道,微信公眾號剛開始的時候接入支付要交巨額的保證金,根據行業不同,金額也不同,但也有大幾萬呢 ...
  • ...
  • 以前一直在用ListView,,,最近才看RecyclerView發現好強大。RecyclerView前提是Android版本在5.0以上,本人以前用的是eclipse只支持到4.4。索性就安裝一個Android Studio去開發RecyclerView吧 真是萬事開頭難,然後中間難,然後結尾難。 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...