IOS 8 - AutoLayout problem - UIImageView inside UITableViewCell, ignoring width limits

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

I developed the view in the interface builder and added the following restrictions (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) 

I also set ImageView to center the image and for subqueries of clips, as well as compression priority 1 (lowest). I also set the UILabel priority of UILabel hugging to 1, so that it even changes if the text is shorter than 120 pixels.

What is happening now:

  • landscape:
    everything works fine
    | Labelxxxxx img1 img2 img3 img4 img5 |
  • portrait mode:
    images refer to something like 10px (this means that it interrupts restriction No. 3 (width 40 pixels) to satisfy restriction No. 1 (width labels), but it does not set the widths of the image representations to 0px that would satisfy restriction # 4 )
    | Labelxxxxx im.im.im.im.im. |

I do not receive any exception or log messages about any unsatisfactory restrictions (not even for the 40px limit, although image views are compressed to 10px)

Thanks in advance for any help you can provide!

- edit -

I tried several alternatives, including setting constraints programmatically, but it looks like they are also configured as intended when using IB.
Is it possible to establish two conflicting restrictions with different priorities - as soon as the one that has a higher priority should be broken down into the advantage of an even higher restriction, the second should be used as a failure?
(In my case: label width = highest priority, gap ImageView width 40px restriction → ImageView width 0px as a failure)

+6
source share
2 answers

I would probably hook IBOutlets to the width constraints and change the width to 0 when rotating.

0
source

I had a similar problem, but it was solved using the following method

  • One DummyView is added inside the UITableViewCell and connect all sides of the DummyView with the UITableViewCell.

  • Now add all the images, shortcuts and other grafts inside the DummyView.

  • Create an IBOutLet to add a DummyView and subView.

  • Programmatically remove all restrictions

  • Programmatically add all restrictions based on device orientation.

0
source

Source: https://habr.com/ru/post/974212/


All Articles