欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

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

 

2.思路:

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

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

(3)循環(huán)算法:當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中解決Xcode 8控制臺亂碼的方式

    iOS中解決Xcode 8控制臺亂碼的方式

    這篇文章給大家介紹了iOS中解決Xcode 8控制臺亂碼的方式,文中給出了詳細解決步驟,相信對大家的理解和學(xué)習(xí)很有幫助,有需要的朋友們下面來一起看看吧。
    2016-10-10
  • iOS實現(xiàn)自定義起始時間選擇器視圖

    iOS實現(xiàn)自定義起始時間選擇器視圖

    本篇文章主要介紹了iOS實現(xiàn)自定義起始時間選擇器視圖,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • iOS NSURLSessionDownloadTask設(shè)置代理文件下載的示例

    iOS NSURLSessionDownloadTask設(shè)置代理文件下載的示例

    本篇文章主要介紹了iOS NSURLSessionDownloadTask設(shè)置代理文件下載的示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • iOS通過block在兩個頁面間傳值的方法

    iOS通過block在兩個頁面間傳值的方法

    不知道大家有沒有發(fā)現(xiàn),在實際開發(fā)中使用block的地方特別多,block比delegate和notification有著更簡潔的優(yōu)勢,下面這篇文章我們來簡單了解一下block在兩個頁面之間的傳值。有需要的朋友們可以參考借鑒,下面來一起學(xué)習(xí)學(xué)習(xí)吧。
    2016-11-11
  • 詳解IOS宏與常量的使用(define,const)

    詳解IOS宏與常量的使用(define,const)

    這篇文章主要介紹了詳解IOS宏define與常量const的使用方法,適合IOS程序員參考,一起來學(xué)習(xí)下。
    2017-12-12
  • 簡單談?wù)凜ore Animation 動畫效果

    簡單談?wù)凜ore Animation 動畫效果

    下面小編就為大家?guī)硪黄唵握務(wù)凜ore Animation 動畫效果。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • 淺談Xcode 開發(fā)工具 XCActionBar

    淺談Xcode 開發(fā)工具 XCActionBar

    本文主要給大家簡單講解了Xcode的開發(fā)工具 XCActionBar的介紹與使用方法,非常的全面實用,有需要的小伙伴可以參考下。
    2015-11-11
  • iOS中長條藍色按鈕(button)實現(xiàn)代碼

    iOS中長條藍色按鈕(button)實現(xiàn)代碼

    本文通過實例代碼給大家介紹了iOS中長條藍色按鈕(button)實現(xiàn)方法,代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
    2017-08-08
  • iOS數(shù)據(jù)持久化UserDefaults封裝器使用詳解

    iOS數(shù)據(jù)持久化UserDefaults封裝器使用詳解

    這篇文章主要為大家介紹了iOS數(shù)據(jù)持久化UserDefaults封裝器使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-02-02
  • iOS archive保存圖片到本地的方法

    iOS archive保存圖片到本地的方法

    這篇文章主要為大家詳細介紹了iOS archive保存圖片到本地的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03

最新評論