【问题标题】:UILabel change height, animation expands from centerUILabel改变高度,动画从中心展开
【发布时间】:2014-09-22 20:54:52
【问题描述】:

我正在尝试使用动画来增加标签高度,但是动画会导致标签首先从中心扩展,然后在正确的 y 点处跳转。这看起来很可怕。我只想扩大底部。

[UIView animateWithDuration:0.5 delay:0.0f options:UIViewAnimationOptionTransitionNone animations:^{

   [self.about increaseHeightFromTopLeft:deltaHeight];

   [self.scrollView increaseContentHeight];

} completion:nil];


- (void)increaseHeightFromTopLeft:(CGFloat ) increased  {

    CGRect newFrame = CGRectMake(self.originX, self.originY, self.frameWidth, self.frameHeight + increased);

    self.frame = newFrame;
}

标签叫做about,你可以在这里看到动画的视频。 https://www.youtube.com/watch?v=DcqktIZ9moY&feature=youtu.be

【问题讨论】:

  • 在我看来,需要动画的是下面的按钮。标签的文本本身不是动画属性。标签可以开始很大,部分被它们共享的子视图上的那些按钮覆盖,然后您更改标签中的文本并滑动按钮
  • 虽然这不是我想要的答案,但我仍然按照您的建议进行操作,而且看起来不错。谢谢

标签: ios animation uiview


【解决方案1】:

遇到同样的问题! 尝试在代码中将标签的 contentMode 设置为 Top:

label.contentMode = UIViewContentModeTop;

【讨论】:

  • 好问题,好答案。他应该接受你的回答。你为我节省了大量时间。谢谢。
  • 很好的答案。但是如果你更喜欢自动布局,你可以在视图下的属性检查器中设置内容模式。我将它设置为 Top 并按预期工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多