国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS模擬中獎(jiǎng)名單循環(huán)滾動(dòng)效果

2020-07-26 02:19:10
字體:
供稿:網(wǎng)友

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

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

 

2.思路:

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

(2)滾動(dòng):使用計(jì)時(shí)器,調(diào)整時(shí)間及滾動(dòng)大小,使展示平滑

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

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

import UIKitclass 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>移動(dòng)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>移動(dòng)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 } //返回行的個(gè)數(shù) func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{  return 10 } //返回列的個(gè)數(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 } //返回一個(gè)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)滾動(dòng)   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í)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 察隅县| 韶山市| 库伦旗| 张家口市| 彰武县| 临汾市| 康马县| 河北省| 石景山区| 白城市| 荥阳市| 平江县| 福州市| 浙江省| 三明市| 安顺市| 安吉县| 忻城县| 神池县| 梅州市| 浦县| 道孚县| 淳化县| 肇东市| 临高县| 华坪县| 宜州市| 缙云县| 五常市| 元氏县| 荔波县| 邵武市| 光泽县| 卓资县| 永川市| 怀柔区| 藁城市| 吉隆县| 津市市| 云南省| 固安县|