iOS 8 - AutoLayout问题 - UITableViewCell内的UIImageView忽略宽度约束

arc*_*cud 6 objective-c uiimageview ios autolayout ios8

我有iOS 8的问题autolayout.
我想要一个UITableviewCell带有a UILabel和5 的自定义UIImageView.我希望图像以横向模式显示,但不能以纵向模式显示,因为这样UILabel会被挤压缩小.

我在界面构建器中设计了视图,并添加了以下约束(以及其他):

 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)
Run Code Online (Sandbox Code Playgroud)

我还设置ImageView为居中图像和剪辑子视图,以及内容压缩优先级为1(最低).该UILabel内容拥抱优先我还设置为1,这样,它甚至调整大小,如果文本比120像素短.

现在发生的事情是:

  • 景观模式:
    一切正常
    | Labelxxxxx img1 img2 img3 img4 img5 |
  • 纵向模式:
    图像视图被挤压到类似10px的东西(这意味着它打破约束#3(40px宽度)以满足约束#1(标签宽度),但它不会将图像视图宽度设置为0px,这将满足约束#4)
    | Labelxxxxx im.im.im.im.im. |

我没有得到任何关于任何不可满足约束的异常或日志消息(即使对于40px约束也没有,尽管图像视图被挤压到10px)

提前感谢您提供的任何帮助!

- 编辑 -

我尝试了一些替代方案,包括以编程方式设置约束,但看起来它们在使用IB时也按预期设置.
难道不可能设置两个具有不同优先级的矛盾约束 - 只要具有更高优先级的约束需要被打破以获得更高约束的优势,第二个应该被用作故障转移?
(在我的情况下:标签宽度=最高优先级,断开ImageView宽度40px约束 - > ImageView宽度0px作为故障转移)

skw*_*hua 0

我可能会将 IBOutlet 连接到宽度约束,并在旋转时将宽度更改为 0。