最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS模擬中獎名單循環(huán)滾動效果

 更新時間:2021年03月19日 15:32:54   作者:???smiling  
這篇文章主要為大家詳細(xì)介紹了iOS模擬中獎名單循環(huán)滾動效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了iOS模擬中獎名單循環(huán)滾動效果的具體代碼,供大家參考,具體內(nèi)容如下

1.動態(tài)效果圖:

 

2.思路:

(1)控件:一個父View,依次添加兩個tableVew,使其上下緊挨著,高度均等于所有cell的總高度,且加載相同的的數(shù)據(jù),父視圖的clipsToBounds屬性一定要設(shè)置為true

(2)滾動:使用計時器,調(diào)整時間及滾動大小,使展示平滑

(3)循環(huán)算法:當(dāng)A列表滾動出界面時,就把它添加在B列表的下面,B列表滾動出界面時,就把它添加在A列表的下面,形成循環(huán)效果

3.Swift版核心代碼(可直接復(fù)制粘貼看效果):

import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{

 var tableView:UITableView!
 var doubleTableView:UITableView!
 let kScreenW = UIScreen.main.bounds.size.width
 let kXPercent = UIScreen.main.bounds.size.width / 375.0
 let kBorderW = CGFloat(15.0)
 let kYPercent = UIScreen.main.bounds.size.width / 375.0
 let cellId:String = "drawViewCell1"

 override func viewDidLoad() {
 super.viewDidLoad()


 self.addListTableView()
 }
 func addListTableView(){

 let tableWidth = kScreenW - kBorderW*3
 let tableBgView = UIView(frame: CGRect(x: (kScreenW-tableWidth)/2.0,y: 100*kYPercent,width: tableWidth,height: 148*kYPercent))
 tableBgView.clipsToBounds = true
 tableBgView.backgroundColor = UIColor.yellow
 self.view.addSubview(tableBgView)

 //

 tableView = UITableView(frame: CGRect(x: 0,y: 0,width: tableWidth,height: 148*kYPercent*2), style: UITableViewStyle.plain)
 tableView.backgroundColor = UIColor.clear
 tableView.delegate = self
 tableView.dataSource = self
 tableView.separatorStyle = UITableViewCellSeparatorStyle.none
 tableBgView.addSubview(tableView)


 doubleTableView = UITableView(frame: CGRect(x: 0,y: tableView.frame.origin.y+tableView.frame.size.height,width: tableWidth,height: 148*kYPercent*2), style: UITableViewStyle.plain)
 doubleTableView.backgroundColor = UIColor.clear
 doubleTableView.delegate = self
 doubleTableView.dataSource = self
 doubleTableView.separatorStyle = UITableViewCellSeparatorStyle.none
 tableBgView.addSubview(doubleTableView)

 //
 Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(personListScroll(timer:)), userInfo: nil, repeats: true)
 }
 @objc func personListScroll(timer:Timer){

 // 1>移動tableView的frame
 var newTableViewframe = self.tableView.frame
 newTableViewframe.origin.y -= 2*kYPercent
 if (newTableViewframe.origin.y < -(doubleTableView.frame.size.height)) {

  newTableViewframe.origin.y = tableView.frame.size.height
 }
 self.tableView.frame = newTableViewframe

 // 2>移動doubleTableView的frame
 var newDoubleViewframe = self.doubleTableView.frame
 newDoubleViewframe.origin.y -= 2*kYPercent
 if newDoubleViewframe.origin.y < -(tableView.frame.size.height) {

  newDoubleViewframe.origin.y = tableView.frame.size.height
 }
 self.doubleTableView.frame = newDoubleViewframe

 }

 //返回行的個數(shù)
 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
 return 10
 }
 //返回列的個數(shù)
 func numberOfSections(in tableView: UITableView) -> Int {
 return 1;
 }
 //去除頭部空白
 func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
 return 0.001
 }
 //去除尾部空白
 func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
 return 0.001
 }
 //返回一個cell
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{

 //回收池
 var cell:UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: cellId)

 if cell == nil{//判斷是否為nil

  cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: cellId)
 }
 cell.backgroundColor = UIColor.clear
 cell.selectionStyle = UITableViewCellSelectionStyle.none

 if tableView == self.tableView{// 測試是否循環(huán)滾動

  cell.textLabel?.text = "張先生"
 }else {

  cell.textLabel?.text = "李小姐"
 }

 return cell
 }
 //返回cell的高度
 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{

 return 148/5.0*kYPercent
 }


 override func didReceiveMemoryWarning() {
 super.didReceiveMemoryWarning()

 }


}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS 微信分享功能簡單實現(xiàn)

    iOS 微信分享功能簡單實現(xiàn)

    本文介紹了iOS 微信分享功能的實現(xiàn)步驟與方法,具有一定的參考作用。下面跟著小編一起來看下吧
    2017-01-01
  • iOS tableview實現(xiàn)簡單搜索功能

    iOS tableview實現(xiàn)簡單搜索功能

    這篇文章主要為大家詳細(xì)介紹了iOS tableview實現(xiàn)簡單搜索功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • IOS倒計時設(shè)置UIButton標(biāo)題title的抖動問題

    IOS倒計時設(shè)置UIButton標(biāo)題title的抖動問題

    這篇文章主要介紹了IOS倒計時設(shè)置UIButton標(biāo)題title的抖動問題,在發(fā)送驗證碼后,button狀態(tài)需要變?yōu)閐isable,每隔一秒顯示倒計時時間,下面通過本文給大家介紹設(shè)置方法,一起看看吧
    2016-12-12
  • IOS 靜態(tài)庫和Framework區(qū)別

    IOS 靜態(tài)庫和Framework區(qū)別

    這篇文章主要介紹了IOS 靜態(tài)庫和Framework區(qū)別的相關(guān)資料,這里對動態(tài)庫與靜態(tài)庫做比較,選擇什么時候使用庫文件,需要的朋友可以參考下
    2016-12-12
  • iOS AFNetworking各種功能封裝類代碼

    iOS AFNetworking各種功能封裝類代碼

    下面小編就為大家分享一篇iOS AFNetworking各種功能封裝類代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • 阿里數(shù)據(jù)iOS端啟動速度優(yōu)化心得

    阿里數(shù)據(jù)iOS端啟動速度優(yōu)化心得

    本篇文章給大家詳細(xì)分析了阿里數(shù)據(jù)iOS端啟動速度優(yōu)化的知識點以及心得,對此有興趣的朋友參考學(xué)習(xí)下吧。
    2018-02-02
  • IOS代碼筆記之下拉菜單效果

    IOS代碼筆記之下拉菜單效果

    這篇文章主要為大家詳細(xì)介紹了IOS實現(xiàn)下拉菜單效果的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-07-07
  • iOS10 ATS 配置詳細(xì)介紹

    iOS10 ATS 配置詳細(xì)介紹

    這篇文章主要介紹了iOS10 ATS 配置詳細(xì)介紹的相關(guān)資料,這里舉例說明該如何配置,需要的朋友可以參考下
    2016-12-12
  • iOS中最全的各種定時器使用教程

    iOS中最全的各種定時器使用教程

    這篇文章主要給大家介紹了關(guān)于iOS中最全的各種定時器的使用教程,文中通過示例代碼介紹的非常詳細(xì),通過文中介紹的最全的定時器相信會對各位iOS開發(fā)者們帶來一定的幫助,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-09-09
  • iOS消息發(fā)送和轉(zhuǎn)發(fā)示例詳解

    iOS消息發(fā)送和轉(zhuǎn)發(fā)示例詳解

    這篇文章主要給大家介紹了關(guān)于iOS消息發(fā)送和轉(zhuǎn)發(fā)的相關(guān)資料,用Objective-C的術(shù)語來講,這叫做“給某個對象發(fā)送某條消息”。文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-03-03

最新評論

清徐县| 沭阳县| 长寿区| 阆中市| 巢湖市| 黄冈市| 岳普湖县| 长顺县| 连南| 姜堰市| 龙南县| 吉首市| 贞丰县| 册亨县| 工布江达县| 奎屯市| 贵德县| 关岭| 澎湖县| 新疆| 朔州市| 苏尼特右旗| 瑞丽市| 卢龙县| 玉门市| 临桂县| 龙泉市| 安新县| 丹东市| 华池县| 东乡县| 墨江| 都兰县| 利津县| 巴里| 怀柔区| 宁明县| 建昌县| 平塘县| 栾城县| 佳木斯市|