0

I have a strange issue with UIButtons inside a UIView. The view is initially constrained to a height of 0, and I'm animating the constraint using

UIView.animateWithDuration(0.6, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {

        heightConstraint!.constant = height
        self.view.layoutIfNeeded()

    }) { (finished) in

    }

This works really well, with all the content of the animated view appearing as expected, apart from any UIButtons that are placed inside.

The buttons' titleLabel font size increases from 0 to the correct size during the animation. There's nothing special about these buttons; they are set to system font of 18, positioned relative to the superview. The button frames are correct, its just the font size that changes.

I've tried explicitly setting adjustsFontSizeToFitWidth and contentMode but these have no effect. Interestingly, if I add a plain UILabel to the view, this works just fine.

Any suggestions as to what is going on?

Graham
  • 6,484
  • 2
  • 35
  • 39

2 Answers2

1

I'm managed to avoid the issue by explicitly setting the height to a non-zero value before the animation:

constraint.constant = 1
self.view.layoutIfNeeded()
self.view.setNeedsUpdateContraints()

// do animation

This resolves the issue, although it feels like a hack around something I'm not doing correctly in the first place.

Graham
  • 6,484
  • 2
  • 35
  • 39
0

Try with clipsToBounds = true, Text is hiding inside the button

When height is 0 or 1, myView is

enter image description here

and after setting clipsToBounds = true, its like this

enter image description here

Note Border = 1 and height = 1 is just to represent here. Even I'm getting this strange issue. But the text do not display after setting the bounds to true

Amit Singh
  • 2,698
  • 21
  • 49