I have a view with a height constraint ≤ constant and a fixed width constraint. Inside it, I have a text view with restrictions on the leading / trailing / top / bottom to this appearance, effectively "docked" inside this view (with only a few points in the field). I have a vertical compression value for vertical content set to 750 and it changes depending on the text content. It grows when I go to the second line, shrinks when I delete a line, etc. However, I want this growth / contraction to be animated. I added this code both to my text view and to the appearance of setFrame: (they are both subclasses):
-(void)setFrame:(CGRect)frame{ [super setFrame:frame]; [UIView animateWithDuration:0.2 animations:^{ [self layoutIfNeeded]; } completion:nil]; }
It does not work, it is still not animated. Then I have subclasses of NSLayoutConstraint and redefined its setConstant: method with the same code:
-(void)setConstant:(CGFloat)constant{ [super setConstant:constant]; if(self.shouldAnimate){ [UIView animateWithDuration:0.2 animations:^{ [self.firstItem layoutIfNeeded]; } completion:nil]; } }
This does not work either. I set a breakpoint inside these methods and they are not called at all. Apparently, the layout changes at a lower level. How can I revitalize the growth and contraction of my look? One of the options is to disable the priority of resistance to compression of content, calculate the height of my text view when changing text, then set the height attribute manually and animate it. But I don’t want to do this if there is a cleaner solution that includes dynamic / automatic resizing using content compression resistance. Is there a solution?
ios objective-c autolayout ios-autolayout
Can poyrazoğlu
source share