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

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

问题描述

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



我正在尝试使用X Code 5和使用StoryBoard执行此操作。



这个问题似乎很简单,但经过几个小时的搜索后,除了一个有点相似但只使用程序化方法的问题之外我什么都没有得到。该示例还包括在uitableviewcell外工作的普通滚动视图。



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

解决方案

在故事板中激活Autolayout(这是一件好事)。
UIScrollView的可滚动大小是根据其子视图的约束计算的。



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



现在,如果你没有向UIImageView添加任何约束,那么将使用其intrinsicContentSize大小。



您的约束应如下所示:





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



完成约束后,从代码中删除所有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天全站免登陆