将UILabel的高度设置为0

Pet*_*lík 1 size height animation uilabel ios

我有一个UILabel,我想要的是将它的高度平滑地改为0.

CGRect newFrame = self.label1.frame;
newFrame.size.height = 0;

[UIView animateWithDuration:1.0 animations:^{

    self.label1.frame = newFrame;
}];
Run Code Online (Sandbox Code Playgroud)

问题是动画干扰了一些奇怪的事情.我想标签正试图调整大小并重新定位它的文本,这就是为什么它不起作用.我尝试过标签上所有可能的属性组合,但没有成功.

Gui*_*ume 7

你可以附上UILabel到另一个UIView,包围设置UIView autoresizesSubviews"属性NOclipToBoundsYES,然后动画封闭的高度UIView...