iOS的8 - 自动版式的问题 - 的UIImageView内的UITableViewCell忽略宽度的限制 [英] iOS 8 - AutoLayout issue - UIImageView inside UITableViewCell ignoring width constraints

查看:141
本文介绍了iOS的8 - 自动版式的问题 - 的UIImageView内的UITableViewCell忽略宽度的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有iOS 8的自动布局的一个问题。结果
我想有一个自定义的的UITableViewCell 的UILabel 5 的UIImageView 。我想在风景模式中显示,但不是在纵向模式的图像,因为这时的UILabel 将被挤压缩小。

I have a problem with iOS 8 autolayout.
I want to have a custom UITableviewCell with a UILabel and 5 UIImageView. I want the images to be shown in landscape-mode but not in portrait mode, because then the UILabel would be squeezed to narrow.

我在设计界面生成器视图并添加下列约束条件(其中包括):

I designed the view in interface builder and added the following constraints (among others):

 1. priority 1000: Label width >= 120px
 2. priority 1000: ImageView[1..5]
    horizontal space to next one = 0px (to align them next to each
    other, the rightmost image view got horizontal space = 0 to content
    view to align them to the right side) 
 3. priority  999: ImageView[1..5]
    width = 40px 
 4. priority  998: ImageView[1..5] width =  0px (hide image
    views if the 40px constraint can't be satisfied because of the
    required label width)

我还设置的ImageView 来居中的形象和剪辑子视图,以及内容融为一体pression优先级1(最低)。
的UILabel 内容拥抱优先级我也设置为1,这样,它甚至调整大小,如果文本比120像素短。

I also set ImageView to center the image and to clip subviews, as well as content compression priority to 1 (lowest). The UILabel content hugging priority I also set to 1 so that it even resizes if the text is shorter than 120px.

现在情况是:


  • 风景模式:结果
    一切工作正常结果
    | Labelxxxxx IMG1 IMG2 IMG3 IMG4 IMG5 |

  • 人像模式:结果
    图像视图被挤压到像10px的(这意味着它打破约束#3(40像素宽度),以满足约束#1(标签宽度),但它不设置图像视图宽度为0px这将满足约束#4 )结果
    | Labelxxxxx im.im.im.im.im. |

  • landscape mode:
    everything works fine
    | Labelxxxxx img1 img2 img3 img4 img5 |
  • portrait mode:
    image views get squeezed to something like 10px (which means that it breaks constraint #3 (40px width) in order to satisfy constraint #1 (label width), but it does not set the image views widths to 0px which would satisfy constraint #4)
    | Labelxxxxx im.im.im.im.im. |

我没有得到任何异常或任何不可满足的约束登录信息(甚至没有为40像素的约束虽然图像视图被挤压为10px)

I don't get any exception or log message about any unsatisfiable constraints (not even for the 40px constraint although the image views get squeezed to 10px)

在此先感谢您的帮助,您可以提供!

Thanks in advance for any help you can provide!

- 编辑 -

我尝试了一些替代方案,包括编程设置约束,但它看起来像他们的使用IB打算时,也被设置。结果
难道不应该是可以设置2不同优先级的矛盾制约 - 只要一个具有更高的优先级需要被打破到一个更高的约束,第二个应该被用作作为故障切换的优点

(在我的情况:标签宽度=最高优先级,中断的ImageView 宽度40像素约束 - > 的ImageView 宽度0像素为失败-over)

I tried some alternatives, including setting the constrains programmatically, but it looks like they are also set as intended when using IB.
Shouldn't it be possible to set 2 contradictory constraints with different priorities - as soon as the one with the higher priority needs to be broken to the advantage of an even higher constraint the second one should be used as as fail-over?
(In my case: label width = highest priority, breaks ImageView width 40px constraint --> ImageView width 0px as fail-over)

推荐答案

我有类似的问题,但通过下面的方法解决。

I had similar issue but solved by following method


  1. 里面的UITableViewCell和引脚DummyView的所有方的UITableViewCell已将1 DummyView。

  1. Added one DummyView inside UITableViewCell and Pin all side of DummyView to UITableViewCell .

现在里面添加DummyView所有图像,标签和其他subiview。

Now add all Image , Label and other subiview inside DummyView.

为您添加DummyView和子视图创建IBOutlet中。

Create IBOutLet for DummyView and subView you added.

编程方式删除所有约束

编程方式添加的所有约束基于设备的方向。

Programmatically add all constraints based on device orientation.

这篇关于iOS的8 - 自动版式的问题 - 的UIImageView内的UITableViewCell忽略宽度的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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