请参阅:Dual Container View Animation iOS,了解我的观点以及我正在尝试做的详细信息。
基本上,它是两个动画的容器视图。在上面描述的主题中,我正在为框架设置动画,我发现这些框架存在问题。
我现在开始设置约束和框架的动画,但是
1)我不确定我所做的事情是否正确。 2)当我旋转设备然后将其旋转回来时,动画视图会向后移动。
如何在激活自动旋转时阻止我的动画视图消失?提前致谢。
我的隐藏/显示代码:
func hideBanner() {
guard isBannerShowing == true else { return }
self.isBannerShowing = false
let adjustment = self.cancelApplyView.frame.size.height
let tableViewFrame = tableContainerView.frame
let newTableViewFrame = CGRect(x: tableViewFrame.origin.x, y: tableViewFrame.origin.y, width: tableViewFrame.size.width, height: tableViewFrame.height + adjustment)
let cancelApplyFrame = cancelApplyView.frame
let newCancelApplyFrame = CGRect(x: cancelApplyFrame.origin.x, y: cancelApplyFrame.origin.y + adjustment, width: cancelApplyFrame.size.width, height: cancelApplyFrame.height)
self.view.updateConstraints()
UIView.animate(withDuration: 0.5, animations: {
self.tableContainerBottomConstraint.constant = 0
self.view.layoutIfNeeded()
self.tableContainerView.frame = newTableViewFrame
self.cancelApplyView.frame = newCancelApplyFrame
})
}
func showBanner() {
guard isBannerShowing == false else { return }
self.isBannerShowing = true
let adjustment = self.cancelApplyView.frame.size.height
let newConstraintVal = cancelApplyView.frame.size.height
let tableViewFrame = tableContainerView.frame
let newTableViewFrame = CGRect(x: tableViewFrame.origin.x, y: tableViewFrame.origin.y, width: tableViewFrame.size.width, height: tableViewFrame.height - adjustment)
let cancelApplyFrame = cancelApplyView.frame
let newCancelApplyFrame = CGRect(x: cancelApplyFrame.origin.x, y: cancelApplyFrame.origin.y - adjustment, width: cancelApplyFrame.size.width, height: cancelApplyFrame.height)
self.view.bringSubview(toFront: self.cancelApplyView)
self.view.updateConstraints()
UIView.animate(withDuration: 0.5, animations: {
self.tableContainerBottomConstraint.constant = newConstraintVal
self.view.layoutIfNeeded()
self.tableContainerView.frame = newTableViewFrame
self.cancelApplyView.frame = newCancelApplyFrame
})
}
答案 0 :(得分:1)
实际上,您不必同时进行自动/帧布局更改
将横幅顶部约束挂钩到桌面并使横幅底部= view.bottom + bannerHeight
隐藏
self.bannerTopConstraint.constant = -1* bannerHeight
self.cancelApplyViewTopConstraint.constant = 0
UIView.animate(withDuration: 0.5, animations: {
self.view.layoutIfNeeded()
})
显示
self.bannerTopConstraint.constant = 0
self.cancelApplyViewTopConstraint.constant = -1 * adjustment
UIView.animate(withDuration: 0.5, animations: {
self.view.layoutIfNeeded()
})