像表格视图单元格一样绘制游戏中心
我现在添加了一项赏金,任何能够拍摄下面三张图片并生成 UITableView 的工作实现(模仿游戏中心游戏中的外观和感觉的 UITableView 的人)都将获得奖励选项卡。该实现必须使用非分组的表格视图,但要演示四个单元格变体(顶部、中间、底部和单个)中的每一个
任何人都可以阐明Apple如何实现游戏中心< /strong> 出现在游戏选项卡上的表格视图单元格?
我特别指的是他们如何绘制边界,以及他们如何让它与底层的绿色噪点纹理混合。
我尝试使用 Quartz 2D 绘制自己的边框,但似乎无法达到相同的质量,并且我认为使用具有较低 alpha 分量的颜色进行绘制可以实现纹理混合,但情况似乎并非如此。
如果有人可以阐明任何观点,甚至分享任何适当的代码,我将非常感激。
编辑:
我注意到表格视图不符合通常的行为。在正常的分组表格视图中,背景是固定的,单元格在其上滚动,但在游戏中心(特别是我关心的表格视图)中,背景与单元格一起滚动。这让我相信桌面视图根本没有分组,这只是 Quartz 2D 绘图和图像混合的幻觉。
编辑:
所以我做了一些探索,看起来苹果确实通过使用标准 tableviewcell、无缝纹理、边框纹理和单元蒙版来创建分组 tableview 的幻觉。所有这些结合起来消除了这种错觉,并支持了我关于为什么背景随单元格滚动的推理(到目前为止我还无法复制)。
游戏中心单元格背景纹理(无缝)
游戏中心单元格边框纹理
游戏中心单元格蒙版
现在我必须弄清楚他们如何将所有这些结合在一起来实现这种幻觉。任何帮助将不胜感激。
实际的 Game Center 表格与@psycho 建议的解决方案之间的差异(您可以在下面看到)仍然有一定的差距;单元格宽度太窄,边框太细,角半径太大。
I've now added a bounty which will be awarded to anyone who can take the three images below and produce a working implementation of a UITableView that mimicks the look and feel of the one found in Game Center on the Games tab. The implementation must use a non-grouped tableview but demostrate each of the four cell variants (top, middle, bottom and single)
Can anyone shed any light on how Apple achieve the Game Center tableview cells which appear on the Games tab?
I'm specifically referring to how they draw the border, and how they seem to get it to blend with the underlying green noisey texture.
I've tried drawing my own borders using Quartz 2D but cannot seem to get anywhere near the same quality, and I thought drawing with a color which had a low alpha component would achive the texture blending but this doesn't seem to be the case.
If anyone can shed any light, or even share any approriate code I would be incredibly greatful.
EDIT:
Something I've noticed is that the tableview doesn't conform to usual behaviour. In a normal grouped tableview the background is stationary and the cells scroll over it, but in Game Center (and specifically the tableview I'm concerned with) the background scrolls with the cells. This is leading me to believe that the tableview is not grouped at all, and this is but an illusion mixing Quartz 2D drawing and images.
EDIT:
So I've done a little poking around, and it does seem as though Apple a creating an illusion of a grouped tableview by using a standard tableviewcell, a seamless texture, a border texture and a cell mask. All this combined pulls off that illusion and supports my reasoning about why the background scrolls with the cells (something I've so far been unable to replicate until now).
Game Center cell background texture (seamless)
Game Center cell border texture
Game Center cell mask
Now I've just got to figure out how they combine all these together to pull off this illusion. Any help will be greatly appreciated.
The differences between the actual Game Center table and the solution @psycho suggested below which you can see is still some way off; the cell widths are too narrow, the border too thin and the corner radius too large.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
他们正在删除所有默认的绘图/边框,并简单地使用带有自己的图像的自定义单元格。
关于您的编辑:这是不正确的。我也实现了这种行为。
,之前,我不记得具体是怎么做到的,我想我直接在表格视图上设置背景图像,而不是它后面的视图。(参见下面的代码。)编辑:
这是我用来模仿单元格“拖动”背景部分的行为的代码:
我已将其放入 UITableViewController 子类中,并在多个实例中继承了该子类。如果仔细观察,细胞外部的“颜色”/纹理会随着细胞移动。
They are removing all of the default drawing/borders and simply using custom cells with their own images.
Regarding your edit: This is incorrect. I've achieved that behavior too.
, before, I don't recall exactly how I did it, I think I set the background image directly on the table view, not the view behind it.(See the code below.)EDIT:
Here's the code I used to mimic the behaviour of cells "dragging" portions of the background with them:
I've put this in a UITableViewController subclass and have inherited from that in several instances. If you look closely, the "color"/texture outside of the cells moves with the cells.
我不确定是否准确回答您的要求,因为我使用了分组的 tableView,但在测试时它似乎可以解决问题,并且背景随单元格滚动,正如在游戏中心中看到的那样。
顺便说一句,抱歉,我不使用 Objective C,而是使用 Monotouch 和 C#,但我从经验中知道,当找到用另一种语言编写的有趣技巧时,找到一种语言到另一种语言的绑定并不难。
好了,别废话了,代码如下。
因此,主要的调整在于使您的 tableView 透明且足够高,以便不需要滚动,并将其粘贴到滚动视图中,滚动视图将滚动其背景及其内容(此处为 tableViews)。
I'm not sure to answer exactly what you asked for because I used a grouped tableView, but when testing it seems to do the trick, and the background scrolls with the cells, as it can be seen in game center.
By the way, sorry, I don't use objective C but Monotouch and C#, but I know from experience it's not so hard to find bindings from one to the other when finding an interesting trick written in another language.
Well, stop babbling, here's the code.
So the main tweak resides in making your tableView transparent and high enough for it to not need scrolling, and to stick it into a scrollView which will scroll its background with its content (here, the tableViews.)