2

I have this code on an UIView subclass:

override var hidden: Bool {
    willSet {
        DDLogDebug("Will set hidden=\(String(newValue)) on \(item?.name))")
    }
    didSet {
        DDLogDebug("Did set hidden=\(String(hidden)) on \(item?.name))")
    }
}

For some reason, I set false but it remains true as seen in these logs:

> Will set hidden=false on Optional("74D8E4CE-5E14-4914-8483-E9F66D2A79B7"))

> Did set hidden=true on Optional("74D8E4CE-5E14-4914-8483-E9F66D2A79B7"))

The only peculiarity of this issue is that it only happens when running inside a UIView.animateWithDuration(...) block. If I remove the animation the property is set correctly.

Any thoughts on what may be going on? This is driving me crazy, heh

Edit:

Little bit more info, this UIView I want to hide is an arrangedSubview of a UIStackView. It works correctly for the first few tries but suddenly stops working without any noticeable pattern.

  • I think you're hitting a stack view bug. See http://stackoverflow.com/questions/33240635/hidden-property-cannot-be-changed-within-an-animation-block – jrturton Aug 20 '16 at 07:36
  • thanks @jrturton for linking that, wondering how that didn't appear in my search results heh, it's definitely a bug in UIStackView and I've fixed it by avoiding setting hidden to the same value twice. Thanks again you made my day! – Nicolas Jakubowski Aug 20 '16 at 14:59

2 Answers2

7

This is a bug in UIStackView.

Here is another question describing the exact same issue I'm having. This is an open radar for this specific issue.

The solution I found was to avoid setting hidden to the same value twice.

if (subview.hidden) {
    subview.hidden = false
}
Community
  • 1
  • 1
  • Thank you so much for this! I have been tracking down an issue similar to this when rotating the device. After more hours and more work arounds than I care to admit to, I found this, which solved the problem. – coping Mar 25 '18 at 22:16
0

try this one, it works for me

[UIView performWithoutAnimation:^{
    arrangedSubview.hidden = isHidden;
}];
leidi
  • 1