【问题标题】:Animation does not Work as Expected While Resizing UIView调整 UIView 大小时动画无法按预期工作
【发布时间】:2023-03-27 07:08:01
【问题描述】:

在我们的问题模块中,当用户单击由 tableview 表示的答案时,我需要调整 UIView 的大小和动画。我已经阅读了一些相关问题并应用了他们的解决方案,但没有一个对我有用。

问题是 uiview 在第一次点击时不会出现,但如果用户点击相同的答案 2 次或更多次,它会出现,因为在第二次点击相同的答案时不会改变框架。

所以基本上如果答案的反馈发生变化,uiview 的高度会被重新计算,我猜它会阻塞动画。

我的视图层次结构: http://i.imgur.com/Oho6Hob.png

改变views和textview约束的方法:

self.feedbackLabelWrapperHeight.constant = height + 45;
self.feedbackViewHeight.constant = height + 45 + 12;
int y = height;

[self.feedbackView setFrame:CGRectMake(50,self.scrollView.frame.size.height + self.scrollView.frame.origin.y -(y+40),self.feedbackView.frame.size.width,(y+40))];

动画方法:

[UIView beginAnimations:@"feedback" context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.2];
[UIView setAnimationDelay:delay];
[self.view layoutIfNeeded];
[UIView commitAnimations];
self.isFeedbackViewVisiable = YES;

我在 didSelectRowAtIndexPath 方法中按以下顺序调用这两个方法: labelHeightOfResponse 参数是相关标签或文本视图的计算高度

[self setFeedbackConstraintHeight:labelHeightOfResponse];
[self feedbackViewAppearAnimationWithDelay:0.2 yPosition:labelHeightOfResponse];

非常感谢您的帮助。 谢谢!

【问题讨论】:

  • 顺便说一下,在日志中计算的视图位置和大小似乎是正确的。
  • 尝试在动画中设置新帧的计算,因此无需调用 layoutIfNeeded
  • 刚刚尝试了您的建议,但不幸的是它也没有奏效。 @JasperPol

标签: ios objective-c cocoa-touch uiview uianimation


【解决方案1】:

花了一个星期后,我添加了一个什么都不做的约束。我不知道为什么,但它解决了动画阻塞问题,而且即使我删除了 layoutIfNeeded,它也能完美运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-22
    • 1970-01-01
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 2011-11-19
    相关资源
    最近更新 更多