Swift版 表情鍵盤展示和仿網易新聞首頁左右滑動

2021-09-11 09:58:32 字數 3841 閱讀 3379

tjtitlestyle.swift  //控制框架所有顯示樣式的引數值

tjtitleview.swift //頂部標題的處理view

tjcontentview.swift //處理所有控制器的view

tjpageview.swift //控制整體框架的總試圖view

複製**

/// 是否是滾動的title

var isscrollenable : bool = false

/// 普通title顏色

var normalcolor : uicolor = uicolor(r: 0, g: 0, b: 0)

/// 選中title顏色

var selectedcolor : uicolor = uicolor(r: 255, g: 127, b: 0)

/// title字型大小

var font : uifont = uifont.systemfont(ofsize: 14.0)

/// 滾動title的字型間距

var titlemargin : cgfloat = 20

/// title的高度

var titleheight : cgfloat = 44

/// 是否顯示底部滾動條

var isshowbottomline : bool = false

/// 底部滾動條的顏色

var bottomlinecolor : uicolor = uicolor.orange

/// 底部滾動條的高度

var bottomlineh : cgfloat = 2

/// 是否進行縮放

var isneedscale : bool = false

var scalerange : cgfloat = 1.2

/// 是否顯示遮蓋

var isshowcover : bool = false

/// 遮蓋背景顏色

var coverbgcolor : uicolor = uicolor.lightgray

/// 文字&遮蓋間隙

var covermargin : cgfloat = 5

/// 遮蓋的高度

var coverh : cgfloat = 25

/// 設定圓角大小

var coverradius : cgfloat = 12

複製**

**如下,注釋比較詳盡,不做贅述

//    在該方法中設定一些必要的layout的結構和初始需要的引數

override func prepare

() prepagecount += (itemcount - 1) / (cols * rows) + 1

}//計算最大寬度

maxwidth = cgfloat(prepagecount) * collectionview!.bounds.width

}複製**

建立collectionview顯示布局內容,設定**方法和對外暴露的方法

**方法
protocol tjpagecollectionviewdatesource : class 

protocol tjpagecollectionviewdelegate : class

複製**

1.設定顯示樣式
let style  = tjtitlestyle()

//是否可以滾動

style.isscrollenable = true

//是否顯示下劃線

style.isshowbottomline = true

//是否顯示遮擋試圖view

style.isshowcover = true

複製**

2.初始化方法
/**初始化方法

* frame : 座標

* titles : 標題陣列

* style : 樣式

* childvcs : 自控制器陣列

* parentvc : 父控制器

*/let pageview = tjpageview(frame: frame, titles: titles, style: style, childvcs: childvcs, parentvc: self)

view.addsubview(pageview)

複製**

// 1.設定顯示樣式

let style = tjtitlestyle()

style.isshowbottomline = true

//2.設定cell布局layout

let layout = tjpagecollectionlayout()

layout.cols = 7 // 列

layout.rows = 3 // 行

layout.minimumlinespacing = 0

layout.minimuminteritemspacing = 0

layout.sectioninset = uiedgeinsets(top: 10, left: 10, bottom: 10, right: 10)

//3.建立collectionview

let pagecollection = tjpagecollectionview(frame: cgrect(x: 0, y: uiscreen.main.bounds.height - 250, width: uiscreen.main.bounds.width, height: 250), style: style, titles: ["普通", "粉絲"], istitleintop: false, layout: layout)

pagecollection.delegate = self

pagecollection.datasource = self

//4.註冊cell

pagecollection.register(nib: uinib(nibname: "emoticonviewcell", bundle: nil), identifier: kemoticoncellid)

//5.新增到檢視中

view.addsubview(pagecollection)

複製**

//mark: tjcollectionviewdatesource

extension nextviewcontroller : tjpagecollectionviewdatesource

func pagecollectionview(_ collectionview: tjpagecollectionview, numberofitemsinsection section: int) -> int

func pagecollectionview(_ pagecollectionview: tjpagecollectionview, _ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell

}//mark: tjpagecollectionviewdelegate

extension nextviewcontroller : tjpagecollectionviewdelegate

}複製**

iOS 聊天表情鍵盤

通過uikeyboardwillchangeframenotification通知,監聽鍵盤的改變,同時可以得到鍵盤的frame和動畫的持續時間,新建鍵盤頂部工具條yscompose 預設在底部,y值隨著鍵盤的改變而改變,會一直顯示在鍵盤的最上面,動畫持續時間使用步驟一通知得到的時間 新建乙個存放表...

Swift中掃瞄emoji表情

emoji表情 對應的十六進製制 let code 0x2605 從字串中取出十六進製制的數 建立乙個掃瞄器,掃瞄器可以從字串中提取我們想要的資料 let scanner nsscanner string code 將十六進製制轉換為字串 var result uint32 0scanner.sca...

iOS開發鍵盤表情處理

概述 原理 將獲取到的字串包含表情進行utf 8轉碼傳給伺服器,然後將伺服器返回的資料解碼,就可以將表情進行上傳 解析等操作,節省大量時間 應用場景 string字串 stringbyaddingpercentescapesusingencoding nsutf8stringencoding 編碼 ...