[英]Subviews of animated UIView not keeping their constraints during animation
我正在为自定义 UIView 设置动画以展开,如下面的 gif 所示(红色视图)。 单击打开/关闭按钮时,我希望左侧图标垂直保持在其超级视图的中心。 如下图所示,只要我点击按钮,图标就会在动画完成后弹出到它应该出现的位置。 按钮也是如此,但它并不那么明显,因为它被暂时隐藏起来,无法点击它。
我还希望UILabel
能够为其大小设置动画,而不是在您单击“关闭”时立即弹出到最小高度。
在 Storyboard 中,我将图标和按钮设置为与超级视图居中对齐,这对我来说似乎是实现我想要的正确方法。 我会假设当我为超级视图设置动画时,子视图将在动画期间保持居中,但它们会立即移动到正确的点,但在动画完成后。
我的动画代码:
UIView.animateWithDuration(0.4, animations: { () -> Void in
var rect = self.frame; //The current frame, to change
let oldHeight = self.frame.size.height as CGFloat
let newSize = self.sizeForBanner() //Get the CGSize for the big banner.
if(self.isBig) //Animate to big size
{
//Put the new height and origin for the large version of the view
rect.size.height = newSize.height;
rect.origin.y -= (rect.size.height - oldHeight)
}else{ //Animate to small size
//Put the new height and origin for the small version of the view
rect.size.height = self.minimalHeight;
rect.origin.y += oldHeight-rect.size.height
}
//Set the new variables
self.frame = rect;
}) { (Bool) -> Void in
//Completion
}
当超级视图动画时,我如何/如何更改以使图标和按钮保持居中?..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.