自定义 UITableViewCell 内的水平 UIScrollView - 使用 IB Storyboard - 不滚动 [英] Horizontal UIScrollView inside custom UITableViewCell - using IB Storyboard - Not scrolling

查看:29
本文介绍了自定义 UITableViewCell 内的水平 UIScrollView - 使用 IB Storyboard - 不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要目标是能够水平滚动每一行的内容.

我正在尝试使用 X Code 5 和 StoryBoard 来做到这一点.

问题似乎很简单,但经过数小时的搜索,除了一个有点相似但仅使用程序化方法的问题外,我一无所获.该示例还包括一个在 uitableviewcell 之外工作的普通"滚动视图.

请说我忽略了一些非常基本的东西.

解决方案

自动布局在您的故事板中被激活(这是一件好事).UIScrollView 的可滚动大小是根据其子视图的约束计算的.

所以你需要在UIScrollView里面的UIImageView上添加top, bottom,leading, trailing space to superview".它们都可以设置为 0.

现在,如果您不向 UIImageView 添加任何约束,则将使用其内部内容大小.

您的约束应如下所示:

请注意,您还缺少对单元格内容视图的约束.

完成约束后,从代码中删除所有 setContentSize: 调用.

The main goal is to be able to scroll each row's content horizontally.

I'm trying to do this with X Code 5 and using StoryBoard.

The problem seems to be simple, but after many hours of searching I got nothing except for one problem that is somewhat similar but using programatic only approachsee here.

In IB, I have the structure as shown in the design below.

  • The content size of the scrollview in set to {5000, 500} set both in IB and in code
  • The scrollview frame is {0,0}{320,44}
  • The labels frame is set to {20,0}{500,44}

I've also provided an example project in a github repository. The example also includes a "normal" scrollview working outside of a uitableviewcell.

Please say that I overlooked something very basic.

解决方案

Autolayout is activated (and that's a good thing) in your storyboard. The scrollable size of a UIScrollView is computed based on the constraints of its subviews.

So you need to add "top, bottom, leading, trailing space to superview" on the UIImageView inside the UIScrollView. They can be all set to 0.

Now if you don't add any constraint to the UIImageView then its intrinsicContentSize size will be used.

Your constraints should look like this:

Note that you were also missing constraints on the content view of your cell.

When you're done with the constraints, remove all the setContentSize: calls from your code.

这篇关于自定义 UITableViewCell 内的水平 UIScrollView - 使用 IB Storyboard - 不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆