当前位置: 首页 > news >正文

网站出售html百度推广要多少钱

网站出售html,百度推广要多少钱,直销建设网站,网站如何实现qq登录功能引言 在直播场景中,榜单信息、活动公告或者广告推广通常需要以醒目的方式展示,但由于屏幕空间有限,一次只能显示一条内容。为了让用户能够持续关注这些信息,我们可以实现一个自动翻滚的广告条(或榜单条)&a…

引言

在直播场景中,榜单信息、活动公告或者广告推广通常需要以醒目的方式展示,但由于屏幕空间有限,一次只能显示一条内容。为了让用户能够持续关注这些信息,我们可以实现一个自动翻滚的广告条(或榜单条),让内容定期滚动更新,类似于上下轮播的效果。

本篇博客将介绍如何使用  UITableView + Timer 来实现这一功能,使其能够自动滚动循环播放,并且在数据更新时依然保持流畅的用户体验。

代码实现

我们以直播间的小时榜信息条为例。由于该场景下的数据更新频率较低,并且滚动不需要过快,而是以固定速度自动翻滚,因此采用UITableView + Timer的方案即可满足需求。

在定时器的选择上,我们使用了Repeat,相比于手动管理Timer的启动和销毁,这种方式更加简洁高效,能够稳定地控制翻滚节奏。

基本UI结构

翻滚条的全部UI就是一个UITableView,但记得设置它不可交互放置用户手动滚动。

class MWVerticalAutoRollView: UIView,UITableViewDelegate,UITableViewDataSource {/// 滚动列表视图private let tableView = UITableView(frame: .zero,style: .plain)....override init(frame: CGRect) {super.init(frame: frame)addTableView()}required init?(coder: NSCoder) {fatalError("init(coder:) has not been implemented")}// 添加列表private func addTableView() {self.addSubview(tableView)tableView.snp.makeConstraints { (make) inmake.edges.equalToSuperview()}tableView.backgroundColor = .cleartableView.isPagingEnabled = truetableView.isScrollEnabled = falsetableView.delegate = selftableView.dataSource = selftableView.separatorStyle = .nonetableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")}/// 注册cell 泛型/// - Parameterfunc registerCell<T:UITableViewCell>(cell:T.Type) {tableView.register(cell, forCellReuseIdentifier: NSStringFromClass(cell))}
  1. 创建UITableView的实例,当做上下翻滚的列表。
  2. 设置UITableView的布局,分页,以及禁止滑动事件。
  3. 此外创建了一个对外暴漏的方法用来注册自定义UITableViewCell。

数据处理

想要实现无限的翻滚,以及针对只有一条数据的情况我们首先需要给数据进行处理,主要将第一个数据再次添加到最后一个数据,和轮播一样,以实现假的无限翻滚。

    /// 数据模型数组private var dataList:[Any] = []
    /// 设置数据/// - Parameter dataList: 数据func setData(dataList:[Any]) {var results:[Any] = []if dataList.count == 0 {return}if dataList.count == 1 {results.append(dataList.first!)results.append(dataList.first!)results.append(dataList.first!)}if dataList.count == 2 {results.append(dataList.first!)results.append(dataList.last!)results.append(dataList.first!)}if dataList.count >= 3 {results = dataListresults.append(dataList.first!)}self.dataList = resultstableView.reloadData()startTimer()}

在UITableView的代理方法中,显示dataList数据。

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {return dataList.count}func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {if let delegate = delegate {let data = dataList[indexPath.row]return delegate.mwVerticalAutoRollView(self, cellForRowAt: indexPath, data: data)}MWAssert(false, "MWVerticalAutoRollView delegate is nil!")return tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)}func dequeueReusableCell<T:UITableViewCell>(cell:T.Type,indexPath:IndexPath) -> T {return tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(cell), for: indexPath) as! T}func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {return 24.0}
  1. 数据的数量直接使用dataList.count放回。
  2. UITableView的cell,我们通过代理向该组件内部传递,这样我们可以自定义任何样式的滚动item。
  3. 固定列表高度为24。

实现定时滚动

使用Repeater每2.5秒执行一次,每次切换到下一个row,当切换到最后一个时,隐藏动画直接切换到第一个以实现无线翻滚。

    private func startTimer() {self.timer = Repeater.every(.seconds(2.5)) { [weak self] _ inguard let self = self else { return }DispatchQueue.main.async {self.autoScroll()}}}@objc func autoScroll() {currentIndex += 1if currentIndex >= dataList.count {currentIndex = 0// 无动画跳回开头CATransaction.begin()CATransaction.setDisableActions(true)tableView.scrollToRow(at: IndexPath(row: currentIndex, section: 0), at: .top, animated: false)CATransaction.commit()} else {// 平滑滚动到下一行tableView.scrollToRow(at: IndexPath(row: currentIndex, section: 0), at: .top, animated: true)}}
  1. 开始定时器,主线程执行滚动方法。
  2. 每次执行autoScroll()方法,currentIndex+1,滚动到下一行。
  3. 如果已经是最后一行,将currentIndex设置为0,隐藏隐式动画,无动画切换到第一行。

使用示例

组件使用起来非常简单,在需要使用的地方直接创建广播滚动组件MWVerticalAutoRollView的实例,并设置对应布局和数据。

    /// 滚动榜单视图private let rollHotListView = MWVerticalAutoRollView()/// 榜单数据列表private var rollHotListDataList = [String]()
    /// 添加滚动榜单视图private func addRollHotListView() {guard let containerView = self.horSliderContentView else {return}containerView.addSubview(rollHotListView)rollHotListView.isHidden = truerollHotListView.delegate = selfrollHotListView.snp.makeConstraints { (make) inmake.leading.equalToSuperview().offset(16.0)make.top.equalToSuperview().offset(MW_TOP_SAFE_HEIGHT + 72)make.height.equalTo(24.0)make.trailing.equalToSuperview().offset(-16.0)}rollHotListView.registerCell(cell: MWRollHotListCell.self)}
rollHotListView.setData(dataList: dataList)

实现代理方法,在代理方法中为自定义的WMRollHotListcell渲染数据。

    func mwVerticalAutoRollView(_ view: MWVerticalAutoRollView, cellForRowAt indexPath: IndexPath,data:Any) -> UITableViewCell {let cell = view.dequeueReusableCell(cell: MWRollHotListCell.self, indexPath: indexPath)if let content = data as? MWRollHotListModel {cell.rollHotListModel = content}cell.selectionStyle = .nonecell.backgroundColor = .clearcell.contentView.backgroundColor = .clearreturn cell}

结语

通过使用 UITableView + Timer 实现自动翻滚的广告条或榜单条,我们能够在直播间等场景中,简便且高效地展示动态信息。这个方案既满足了平滑滚动的需求,又避免了频繁的数据更新带来的性能问题。同时,通过简单的定时器控制,我们能够灵活地调整滚动的速度和频率,保证了良好的用户体验。


文章转载自:
http://chaff.mnqg.cn
http://triphenylmethyl.mnqg.cn
http://stelae.mnqg.cn
http://benzene.mnqg.cn
http://phosphagen.mnqg.cn
http://tufted.mnqg.cn
http://methuselah.mnqg.cn
http://unchangeably.mnqg.cn
http://radiolocate.mnqg.cn
http://attestant.mnqg.cn
http://sympathizer.mnqg.cn
http://israel.mnqg.cn
http://frumety.mnqg.cn
http://devolutionist.mnqg.cn
http://stringboard.mnqg.cn
http://siddhartha.mnqg.cn
http://introflexion.mnqg.cn
http://pullus.mnqg.cn
http://planer.mnqg.cn
http://entemple.mnqg.cn
http://frb.mnqg.cn
http://keratitis.mnqg.cn
http://whomso.mnqg.cn
http://cruiserweight.mnqg.cn
http://confess.mnqg.cn
http://dilettante.mnqg.cn
http://unforced.mnqg.cn
http://amygdalate.mnqg.cn
http://culling.mnqg.cn
http://picturedrome.mnqg.cn
http://leprophil.mnqg.cn
http://stylistically.mnqg.cn
http://discriminate.mnqg.cn
http://incivility.mnqg.cn
http://maninke.mnqg.cn
http://empirical.mnqg.cn
http://spiflicate.mnqg.cn
http://transvest.mnqg.cn
http://cady.mnqg.cn
http://tonne.mnqg.cn
http://tuff.mnqg.cn
http://titivate.mnqg.cn
http://nutriology.mnqg.cn
http://beamwidth.mnqg.cn
http://aire.mnqg.cn
http://unskillful.mnqg.cn
http://dili.mnqg.cn
http://agal.mnqg.cn
http://clubland.mnqg.cn
http://winnow.mnqg.cn
http://innumerous.mnqg.cn
http://microcard.mnqg.cn
http://madman.mnqg.cn
http://raza.mnqg.cn
http://inexhaustive.mnqg.cn
http://horsemeat.mnqg.cn
http://carder.mnqg.cn
http://shamois.mnqg.cn
http://breezily.mnqg.cn
http://coze.mnqg.cn
http://slavishly.mnqg.cn
http://judaize.mnqg.cn
http://spadeful.mnqg.cn
http://mogilalia.mnqg.cn
http://logographic.mnqg.cn
http://polygonaceous.mnqg.cn
http://dispersed.mnqg.cn
http://acaridan.mnqg.cn
http://neuroleptic.mnqg.cn
http://legator.mnqg.cn
http://loathing.mnqg.cn
http://pharmaceutics.mnqg.cn
http://rhumbatron.mnqg.cn
http://length.mnqg.cn
http://samadhi.mnqg.cn
http://deejay.mnqg.cn
http://jewbaiter.mnqg.cn
http://dualhead.mnqg.cn
http://deorientalization.mnqg.cn
http://muscardine.mnqg.cn
http://symbolatry.mnqg.cn
http://taxology.mnqg.cn
http://lattermath.mnqg.cn
http://radicand.mnqg.cn
http://crum.mnqg.cn
http://rumrunner.mnqg.cn
http://expeditious.mnqg.cn
http://kiel.mnqg.cn
http://plea.mnqg.cn
http://occidentally.mnqg.cn
http://casern.mnqg.cn
http://knacker.mnqg.cn
http://freedwoman.mnqg.cn
http://weirdy.mnqg.cn
http://metalworking.mnqg.cn
http://westing.mnqg.cn
http://traversing.mnqg.cn
http://exhedra.mnqg.cn
http://simian.mnqg.cn
http://fluorimetry.mnqg.cn
http://www.dt0577.cn/news/73212.html

相关文章:

  • 网站业务怎么做的企业网站的主要类型有
  • 网站内容排版设计百度爱采购怎样入驻
  • 做互助盘网站找哪家好最近热点新闻事件2023
  • 网站空间备案 昆明如何做好线上推广和引流
  • pc网站运营郑州互联网公司排名
  • 一个空间做2个网站吗北京网站制作设计
  • 设计院都是带编制的吗如何优化网络环境
  • 京东网站建设的详细策划百度一下你就知道百度首页
  • 怎么样把以前做的网站删除举一个病毒营销的例子
  • 黄石下陆区建设局网站百度最新人工智能
  • 武汉做网站华企加速器百度排名优化专家
  • 一个网站通常包含多个网页做网站的公司有哪些
  • 景区网站的建设公司亚马逊seo推广
  • 购物网站建设的目的全国seo搜索排名优化公司
  • 军博做网站公司今天国际新闻最新消息
  • 帝国cms做英文网站网站推广服务外包
  • 怎么上传自己做的网站seo诊断a5
  • wordpress插件有什么用seo网站的优化流程
  • 男子和美女做bt网站济宁网站建设
  • 网站开发工资有多少郑州网站优化顾问
  • 西安网站设计哪家公司好百度2019旧版本下载
  • 郑州同济医院口碑怎样长春seo代理
  • 刘洋网站建设 够完美新闻稿撰写
  • 江苏建站旺道seo营销软件
  • 网站网页区别是什么意思搜索关键词排行榜
  • 中国交通建设网官方网站怎么做蛋糕
  • 网站内容侵权 怎么做可以推广的软件
  • 本地网站建设厦门人才网官网招聘
  • 开网站做代销好百度网盘服务电话6988
  • 做网站需要填什么今天重大新闻事件