gpt4 book ai didi

ios - 在 UIViewController View 上对 subview 进行动画处理

转载 作者:行者123 更新时间:2023-11-29 01:53:52 25 4
gpt4 key购买 nike

我将 UITableView 作为 UIViewController 的 UIView(父 View )的 subview 。当我如下动画我的父 View 时:

       UIView.animateWithDuration(duration, animations: {
viewController?.view.frame = CGRectMake(0,0,320,568)
}, completion: {_ in

})

我发现我的 subview (表格 View )没有动画。我尝试将 subview 的自动调整大小掩码设置为 flexibleWidth 和 flexibleHeight,但没有取得任何成功。任何人都知道为什么会这样。

最佳答案

如果您正在使用自动布局(这是 Xcode 6/7 上 iOS 8/9 中的默认设置),您需要更改 UIView 动画闭包中 View 的约束,而不是更改框架。

如果您没有使用自动布局,那么您可以像上面那样更新框架,但是,我想您是。因此,您需要调用 layoutSubviews,然后以编程方式设置代表您对布局进行的所需更改的新约束,最后在动画闭包内再次调用 layoutSubviews

例子:

func AnimateBackgroundHeight() {
self.view.layoutSubviews()
UIView.animateWithDuration(0.5, animations: {
self.heightCon.constant = 600 // heightCon is the IBOutlet to the constraint
self.view.layoutSubviews()
})
}

关于ios - 在 UIViewController View 上对 subview 进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31101813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com