热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何用水平滚动列表创建TabelView-IOS-HowtocreateTabelViewwithhorizontalscrollablelists

Imtryingtoimplementatableviewwithscrollablehorizontalitems(withunknownnumberofitems)

I'm trying to implement a table view with scrollable horizontal items (with unknown number of items) like the illustration below:

我正在尝试使用可滚动的水平项目(项目数量未知)实现一个表视图,如下图所示:

enter image description here

The UI should behave like so:

UI应该这样做:

  1. At the init state the table cell shows a label and some text and the circle item pops out of the right side
  2. 在init状态下,表单元格显示一个标签和一些文本,圆圈项从右侧弹出
  3. If the users swipes from right to left, the label and text fades out and the horizontal list (inside the cell) takes it's place
  4. 如果用户从右向左滑动,标签和文本就会消失,而水平列表(在单元格内)就会取代它。

I thought about using TableView and dequeueReusableCellWithIdentifier and creating a prototype cell, but then I need to remember the list horizontal position and init the cell properly on cellForRowAtIndexPath and that will probably affect performance.

我考虑过使用TableView和dequeueReusableCellWithIdentifier并创建一个原型单元格,然后我需要记住列表水平位置并在cellForRowAtIndexPath上正确初始化单元格,这可能会影响性能。

Q: What layout would you use in order to achieve this goal, any input / tutorial would be appreciated

问:为了达到这个目标,你会使用什么样的布局,任何输入/教程都会受到欢迎

3 个解决方案

#1


40  

Use a UITableView and add a UICollectionView to your reusable tableView cell. UICollectionView works similar to UITableView in that the "items" (like cells) are reusable and instantiated only when they will appear on screen. I did a quick google search for tutorials and found UICollectionView in UITableViewCell. Check that out and a few other StackOverflow questions regarding design and you should be golden.

使用UITableView并向可重用的tableView单元格添加UICollectionView。UICollectionView的工作原理与UITableView相似,因为“项目”(如单元格)只有在它们出现在屏幕上时才会被重用和实例化。我做了一个快速的谷歌搜索教程,并在UITableViewCell中找到了UICollectionView。看看这一点,再看看其他一些关于设计的问题,你会发现你是最棒的。

#2


4  

You can use a ScrollView to put inside your tableview and set the values "Direction lock enabled" and "Paging Enabled" to true for the scrollview.

您可以使用ScrollView将值放在tableview中,并将ScrollView的“方向锁定”和“分页启用”的值设置为true。

#3


2  

Using UIScrollView may require heavy effort if there are large amount of UI elements inside each scrollview because you have to instantiate all those upfront. A better solution is to define your custom UITableViewCell which has its own UITableView but rotated in 90 degree for horizontal scrolling. UI elements inside will be created only when they need to be shown by using dequeueReusableCellWithIdentifier:forIndexPath:. Please see some sample code on how to create a 90 degree rotated table view:

如果每个scrollview中都有大量的UI元素,那么使用UIScrollView可能需要付出很大的努力,因为您必须首先实例化所有这些元素。更好的解决方案是定义自定义的UITableViewCell,它有自己的UITableView,但在水平滚动时旋转90度。只有当需要使用dequeueReusableCellWithIdentifier:forIndexPath:来显示UI元素时,才会创建UI元素。请参阅一些关于如何创建90度旋转表视图的示例代码:

iPhone Tableview Use Cells in Horizontal Scrolling not Vertical

iPhone Tableview使用的单元格是水平滚动,而不是垂直滚动


推荐阅读
  • 拥抱Android Design Support Library新变化(导航视图、悬浮ActionBar)
    转载请注明明桑AndroidAndroid5.0Loollipop作为Android最重要的版本之一,为我们带来了全新的界面风格和设计语言。看起来很受欢迎࿰ ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • Ihavethefollowingonhtml我在html上有以下内容<html><head><scriptsrc..3003_Tes ... [详细]
  • 网址:https:vue.docschina.orgv2guideforms.html表单input绑定基础用法可以通过使用v-model指令,在 ... [详细]
  • 本文介绍了一款名为TimeSelector的Android日期时间选择器,采用了Material Design风格,可以在Android Studio中通过gradle添加依赖来使用,也可以在Eclipse中下载源码使用。文章详细介绍了TimeSelector的构造方法和参数说明,以及如何使用回调函数来处理选取时间后的操作。同时还提供了示例代码和可选的起始时间和结束时间设置。 ... [详细]
  • 带添加按钮的GridView,item的删除事件
    先上图片效果;gridView无数据时显示添加按钮,有数据时,第一格显示添加按钮,后面显示数据:布局文件:addr_manage.xml<?xmlve ... [详细]
  • 本文整理了Java中java.lang.NoSuchMethodError.getMessage()方法的一些代码示例,展示了NoSuchMethodErr ... [详细]
  • ASP.NET2.0数据教程之十四:使用FormView的模板
    本文介绍了在ASP.NET 2.0中使用FormView控件来实现自定义的显示外观,与GridView和DetailsView不同,FormView使用模板来呈现,可以实现不规则的外观呈现。同时还介绍了TemplateField的用法和FormView与DetailsView的区别。 ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
author-avatar
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有